#include #include #include #include #define N 10000005 using namespace std; typedef long long ll; char ch[N]; int a[N],v[20],T,i,n,t,num,len; int main() { scanf("%d", &T); while (T--) { for (i=1;i<=10000000;i++) ch[i]=0; scanf("%s",ch+1); for (i=0;i<=9;i++) v[i]=0; n=strlen(ch+1); for (i=1; i<=n; i++) v[ch[i]-'0']++; if (v[1]+v[2]+v[3]+v[4]+v[5]+v[6]+v[7]+v[8]+v[9] < 2) { puts("Uncertain"); continue; } for (i=1;i<=9;i++) if (v[i]){t=i;v[i]--;break;} a[n]=0;num=n-1; for (i=9;~i;i--) while (v[i]--) a[num--]=i; a[1]+=t; for (i=1;i<=n-1;i++) { a[i+1]+=a[i]/10; a[i]%=10; } len=n; if (!a[n]) len--; for (i=len;i>=1;i--) printf("%d", a[i]); puts(""); } }