#include #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; inline int isnum(const char c) { if (c >= '0' and c <= '9') { return c - '0'; } else { return -1; } } inline char nextch(const char c, bool& car) { if (c != '9') { car = false; return c + 1; } else { car = true; return '0'; } } string inc(const string& str) { string s = str; bool car = true; for (int i = str.size() - 1; i >= 0; i--) { if (not car) { break; } const char next = nextch(s[i], car); s[i] = next; } if (car) { s = "1" + s; } return s; } int main() { int T; cin >> T; string dummy; getline(std::cin, dummy); for (auto t = 0; t < T; t++) { string s; getline(std::cin, s); int i = s.size() - 1; bool flag = true; int tail = 0; int pos = -1; bool trail = false; bool contain = false; int size = 0; string stnum; for (; i >= 0 and flag;) { if (isnum(s[i]) == -1) { i--; continue; } else { contain = true; tail = max(tail, i); while (i >= 0) { if (isnum(s[i]) != -1) { stnum.push_back(s[i]); } else { pos = i; flag = false; break; } i--; } reverse(stnum.begin(), stnum.end()); if (stnum[0] == '0') { trail = true; size = stnum.size(); } } } if (not contain) { cout << s << endl; continue; } string newst = inc(stnum); const int prev_size = newst.size(); if (trail) { for (int i = 0; i < size - prev_size; i++) { newst = "0" + newst; } } for (int i = 0; i <= pos; i++) { cout << s[i]; } cout << newst; for (int i = tail + 1; i < s.size(); i++) { cout << s[i]; } cout << endl; } return 0; }