// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; int T; string s; void main() { scan(T); while (T--) { s = readln.chomp; writeln(solve(s)); } } string solve(string s) { int n = s.length.to!int; int r = -1; foreach_reverse (i ; 0 .. n) { if ('0' <= s[i] && s[i] <= '9') { r = i + 1; break; } } if (r == -1) return s; int l = 0; foreach_reverse (i ; 0 .. r) { if (s[i] < '0' || s[i] > '9') { l = i + 1; break; } } return s[0 .. l] ~ increment(s[l .. r]) ~ s[r .. $]; } string increment(string t) { int n = t.length.to!int; char[] res = ("0" ~ t).to!(char[]); bool flag = 1; int r = n; while (flag) { if (r == 0) { break; } if (res[r] == '9') { res[r] = '0'; } else { res[r] += 1; flag = 0; } r--; } if (flag) res[0] = '1'; else res = res[1 .. $]; return res.to!string; } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }