#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; #include namespace mp = boost::multiprecision; int main() { int n; cin >> n; regex re("^(\\D*)(\\d+)(.*)$"), re2("^(0*)([1-9]\\d*)$"); string s; getline(cin, s); while (n--) { getline(cin, s); reverse(s.begin(), s.end()); smatch m; if (regex_search(s, m, re)) { string t = ""; string u = m[3]; reverse(u.begin(), u.end()); t += u; u = m[2]; reverse(u.begin(), u.end()); smatch m2; if (regex_search(u, m2, re2)) { string m21 = m2[1], m22 = m2[2]; mp::cpp_int x(m22); x++; if (m21.size() == 0) { t += x.str(); } else { if (m22.size() == x.str().size()) { t += m21; t += x.str(); } else { assert(m22.size() + 1 == x.str().size()); t += m21.substr(0, m21.size() - 1); t += x.str(); } } } else { t += u.substr(0, u.size() - 1); t += '1'; } u = m[1]; reverse(u.begin(), u.end()); t += u; cout << t << endl; } else { reverse(s.begin(), s.end()); cout << s << endl; } } }