#include #include #include //#include //#include using namespace std; long long MODA = 1000000007ll; const int MAXN = 200050; inline void print(char pt) { printf("%c\n", pt); } inline void print(int pt) { printf("%d\n", pt); } inline void print(long long pt) { printf("%I64d\n", pt); } inline void print(double pt) { printf("%f\n", pt); } inline void print(char pt[]) { printf("%s\n", pt); } inline void scan(int &pt) { scanf("%d", &pt); } inline void scan(char &pt) { scanf("%c", &pt); } inline void scan(long long &pt) { scanf("%I64d", &pt); } inline void scan(double &pt) { scanf("%lf", &pt); } inline void scan(char pt[]) { scanf("%s", pt); } struct pii { int a; int b; friend int operator<(pii a, pii b) { if (a.a != b.a) return a.a < b.a; return a.b < b.b; } }; struct str { char val[1005]; str() { memset(val, 0, sizeof(val)); } friend int operator<(str a, str b) { return strcmp(a.val, b.val) < 0; } }; //int gcd(int x, int y) { // return y ? gcd(y, x % y) : x; //} //int lcm(int x, int y) { // return x * (y / gcd(x, y)); //} long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); } int bits[50]; void getbits() { for (int i = 0; i < 30; i++) { bits[i] = 1 << i; } } long long Q_pow(long long x, long long y) { long long res = 1; while (y) { if (y % 2 == 1) { res *= x; res %= MODA; } x = x * x; x %= MODA; // if(x<=1e-5){ // return 0; // } y /= 2; } return res; } //返回d=gcd(a,b);和对应于等式ax+by=d中的x,y long long extend_gcd(long long a, long long b, long long &x, long long &y) { if (a == 0 && b == 0) return -1; //无最大公约数 if (b == 0) { x = 1; y = 0; return a; } long long d = extend_gcd(b, a % b, y, x); y -= a / b * x; return d; } //*********求逆元素******************* //ax = 1(mod n) long long mod_reverse(long long a, long long MOD) { long long x, y; long long d = extend_gcd(a, MOD, x, y); if (d == 1) return (x % MOD + MOD) % MOD; else return -1; } int father[1000050]; int findfather(int x) { return father[x] == x ? x : father[x] = findfather(father[x]); } int n, m, k, t; char stra[10000050]; int b[10000050]; map mapa; int main() { scan(n); int tn = n; while (tn--) { mapa.clear(); scan(stra); int lena = strlen(stra); for (int i = 0; i < lena; i++) { mapa[stra[i] - '0']++; } int flag0 = 0; for (map, allocator > >::iterator it = mapa.begin(); it != mapa.end(); it++) { //cout << it->first << " " << it->second << endl; if (it->first != 0) { flag0 += it->second; } } if (flag0 <= 1) { printf("Uncertain\n"); continue; } int numb; for (map, allocator > >::iterator it = mapa.begin(); it != mapa.end(); it++) { if (it->first != 0) { //cout<first<<"kaka"<second<<"kaka"<first]--; numb = it->first; break; } } memset(b, 0, sizeof(b)); int ind = 0; for (map, allocator > > ::iterator it = mapa.begin(); it != mapa.end(); it++) { for (int i = 0; i < (it->second); i++) { b[ind] = it->first; ind++; } } b[0] += numb; for (int i = 0; i < ind; i++) { if (b[i] >= 10) { b[i] -= 10; b[i + 1]++; if (i + 1 == ind) ind++; } } for (int i = ind - 1; i >= 0; i--) { printf("%c", '0' + b[i]); } printf("\n"); } return 0; }