#include #include #include #include #include #include #include #include #include #include #include #define LL long long #define ULL unsigned long long #define pii pair #define xx first #define yy second #define ls rt << 1 #define rs rt << 1 | 1 #define lson ls, l, m #define rson rs, m + 1, r using namespace std; const int mod = 1e9 + 7, N = 10010000; int c[12]; char s[N], t[N]; int pm (LL x, int y) { LL r = 1; while (y) { if (y & 1) r *= x, r %= mod; x *= x, x %= mod; y >>= 1; } return r; } int main () { // freopen ("in.txt", "r", stdin); int T, k, n, m; cin >> T; getchar (); while (T--) { memset (c, 0, sizeof c); gets (s); int len = strlen (s); for (int i = 0; i < len; i++) { c[s[i] - '0']++; } if (len - c[0] <= 1) { cout << "Uncertain\n"; continue; } int tmp; for (int i = 1; i <= 9; i++) if (c[i]) { c[i]--; tmp = i; break; } t[0] = '0'; int tn = 1; // int now = 0; for (int i = 9; i >= 0; i--) { for (int j = 0; j < c[i]; j++) { t[tn++] = i + '0'; } } t[tn] = 0; t[tn - 1] += tmp; for (int i = tn - 1; i >= 0; i--) { if (t[i] > '9') t[i] -= 10, t[i - 1]++; } if (t[0] == '0') puts (t + 1); else puts (t); } }