#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; } } 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 = 0; ll numnum = 0; bool trail = false; bool contain = false; int size = 0; for (; i >= 0 and flag;) { if (isnum(s[i]) == -1) { i--; continue; } else { contain = true; tail = max(tail, i); string stnum; 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(); } numnum = stoll(stnum); } } if (not contain) { cout << s << endl; continue; } numnum++; string newst = to_string(numnum); const int prev_size = newst.size(); if (trail) { for (int i = 0; i < size - prev_size - 1; 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; }