#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { string s; do { getline(cin, s); } while (s.size() < 1); int n = s.size(); bool b = false, b3 = false; for (int j = n - 1; j >= 0; j--) { if (isdigit(s[j])) { b3 = true; if (s[j] == '9') { break; } s[j]++; cout << s << endl; b = true; break; } } if (!b3) { cout << s << endl; continue; } bool b1 = false; if (!b) { bool b2 = false; for (int j = n - 1; j >= 0; j--) { if (s[j] == '9') { b1 = true; s[j] = '0'; } else if (b1 && !isdigit(s[j])) { string ans = s.substr(0, j + 1) + '1' + s.substr(j + 1, n - j - 1); cout << ans << endl; b2 = true; break; } else if (b1 && s[j] >= '0' && s[j] <= '8') { s[j]++; cout << s << endl; b2 = true; break; } } if (!b2) { s = '1' + s; cout << s << endl; } } } return 0; }