#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin >> T; cin.ignore(); rep(_,T) { string s; getline(cin, s); vector> v; v.push_back({!!isdigit(s[0]), string(1, s[0])}); for(int i = 1; i < int(s.size()); i++) { if(v.back().first == !!isdigit(s[i])) v.back().second += s[i]; else v.push_back({!!isdigit(s[i]), string(1, s[i])}); } int MAX = -1, ARGMAX = -1; rep(i,v.size()) { auto &[f, s] = v[i]; if(f) { if(MAX <= int(s.size())) { MAX = int(s.size()); ARGMAX = i; } } } if(ARGMAX == -1) { cout << s << "\n"; } else { string &t = v[ARGMAX].second; int k = 1; for(int i = int(t.size()) - 1; i >= 0; i--) { if(k == 1) { if(t[i] == '9') { t[i] = '0'; k = 1; } else { t[i]++; k = 0; } } } if(k == 1) t = '1' + t; string ans = ""; for(auto [f, s] : v) ans += s; cout << ans << endl; } } }