using System; using System.Linq; namespace y { class Program { static void Main(string[] args) { int t = int.Parse(Console.ReadLine()); for (int i = 0; i < t; i++) { string s = Console.ReadLine(); int nn = s.Length - 1; for (int j = s.Length - 1; j >= 0; j--) { if ('0' <= s[j] && s[j] <= '9') { } else { nn = j + 1; break; } } string ns = ""; bool f = false; if (nn != s.Length) { int newNum = int.Parse(s.Substring(nn)) + 1; if (newNum.ToString().Length != s.Substring(nn).Length) { f = true; } ns = newNum.ToString(); } int aaa = ns.Length; if (f) { aaa--; } string ans = s.Substring(0, s.Length - aaa) + ns; Console.WriteLine(ans); } } } }