#include #include #include #include using namespace std; int T,n; const int maxn = 10000010; int vis[10]; int a[maxn]; int b; int len; int mark; void read() { char c = getchar(); while(c<'0'&&c>'9') c=getchar(); while(c>='0'&& c<='9') { vis[c-'0']++; ++len; c = getchar(); } mark = len - vis[0]; } int main() { scanf("%d",&T); while(T--) { memset(vis,0,sizeof(vis)); len = 0; scanf("\n"); read(); int lenth = len; if(mark<2) { printf("Uncertain\n"); continue; } int pos = 0; bool flag=0; a[0]=0; for(int i=9;i>=0;i--) { while(vis[i]) { if(mark>1||flag) { a[++pos] = i; vis[i]--; mark--; len--; } else if(!flag) { b = i; vis[i]--; mark--; len--; flag=1; } } if(!len)break; } a[pos] += b; int now = pos; while(a[now]>9) { a[now]-=10; now--; a[now]++; } if(!a[0]&&!a[1]) { printf("0\n"); continue; } else if(a[0])printf("%d",a[0]); for(int i = 1;i<=pos;i++)printf("%d",a[i]); printf("\n"); } return 0; }