/* *********************************************** Author :Stomach_ache Created Time :Sun 17 Jul 2016 06:04:31 PM CST File Name :A.cpp ************************************************ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if __cplusplus > 201103L #include #include #include #endif using namespace std; #define oo 0x3F3F3F3F #define PB push_back #define SZ(x) (int)((x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (int _end_ = (b), i = (a); i <= _end_; ++i) #define ROF(i, a, b) for (int _end_ = (b), i = (a); i >= _end_; --i) typedef unsigned int uint; typedef long long int64; typedef unsigned long long uint64; typedef long double real; int64 fpm(int64 b, int64 e, int64 m) { int64 t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template inline bool chkmin(T &a, T b) {return a > b ? a = b, true : false;} template inline bool chkmax(T &a, T b) {return a < b ? a = b, true : false;} template inline T sqr(T x) {return x * x;} template T gcd(T x, T y) {for (T t; x; ) t = x, x = y % x, y = t; return y; } char s[10000010]; int main(void) { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T; scanf("%d", &T); for (int t = 1; t <= T; ++ t) { vector cnt(10, 0); scanf("%s", s); int n = strlen(s); for (int i = 0; i < n; ++ i) { ++ cnt[s[i] - '0']; } int cc = 0; for (int i = 1; i <= 9; ++ i) if (cnt[i] > 0) { cc += cnt[i]; if (cc > 1) break; } if (cc <= 1) { printf("Uncertain\n"); } else { int last = 0; for (int i = 1; i < 10; ++ i) if (cnt[i] > 0) { -- cnt[i]; last = i; break; } int j = 0; int c = last; for (int i = 0; i < 10; ++ i) { while (cnt[i] > 0) { s[j ++] = (c + i) % 10 + '0'; c = (c + i) / 10; -- cnt[i]; } } if (c > 0) s[j ++] = c + '0'; for (int i = j - 1; i >= 0; -- i) printf("%c", s[i]); printf("\n"); } } return 0; }