#include #include #include #include #include #include using namespace std; int a[10]; const int N = 10000010; char str[N]; int main(void) { int T; scanf("%d", &T); int i; while(T--) { int flag = 0; char c = 0; memset(a, 0, sizeof(a)); memset(str, '0', sizeof(str)); while('0' > c || c > '9') c = getchar(); while(c != '\n') { a[ c-'0' ]++; c = getchar(); } for(i = 1; i < 10; i++) flag += a[i]; if(flag < 2) { printf("Uncertain\n"); continue; } int tmp = 0; for(i = 1; i < 10; i++) { if(a[i]) { tmp = i; a[i] -= 1; break; } } int cnt = 0; int first = 0; for(i = 0; i < 10; i++) { if(!first && a[i]) { first = 1; str[cnt++] = '0' + (i+tmp)%10; tmp = (i+tmp)/10; a[i]--; } while(a[i]) { str[cnt++] = '0'+(tmp+i)%10; tmp = (tmp+i)/10; a[i]--; } } if(tmp) str[cnt] = '1'; if(tmp) i = cnt; else i = cnt-1; for(; i >= 0; i--) putchar(str[i]); putchar('\n'); } return 0; }