#define _CRT_SECURE_NO_WARNINGS #include using namespace std; char str[10000005]; size_t numCount[10]; char charSet[] = { '0','1','2','3','4','5','6','7','8','9' }; void setOutstr() { char *ptr = str; for (int i = 9; i >= 0; --i) for (size_t j = 0; j < numCount[i]; ++j) *(ptr++) = charSet[i]; *ptr = '\0'; } int main() { int N; cin >> N; while (N--) { memset(numCount, 0, sizeof(numCount)); scanf("%s", str); size_t length = strlen(str); for (size_t i = 0; i < length; ++i) ++numCount[str[i] - '0']; size_t noneZeroCount = length - numCount[0]; if (noneZeroCount <= 1) printf("Uncertain\n"); else { char needAdd; for (size_t i = 1; i <= 9; ++i) if (numCount[i] != 0) { --numCount[i]; needAdd = i; break; } setOutstr(); char *ptr = &str[length - 2]; //printf("*ptr = %c \n", *ptr); while (ptr >= str) { *ptr += needAdd; if (*ptr <= '9') break; needAdd = 1; *ptr -= 10; --ptr; } if (ptr < str) printf("1"); printf("%s\n", str); } } #ifndef ONLINE_JUDGE system("pause"); #endif return 0; }