#pragma warning disable IDE0011 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using static System.Convert; using static System.Math; using static Extentions; class IO { int idx; string[] line; public void R(params char[] sep) { line = Console.ReadLine().Split(sep); idx = 0; } public string S => line[idx++]; public string[] Ss => line.Skip(idx++).ToArray(); public char C => char.Parse(line[idx++]); public char[] Cs => line.Skip(idx++).Select(char.Parse).ToArray(); public int I => int.Parse(line[idx++]); public int[] Is => line.Skip(idx++).Select(int.Parse).ToArray(); public long L => long.Parse(line[idx++]); public long[] Ls => line.Skip(idx++).Select(long.Parse).ToArray(); public double F => double.Parse(line[idx++]); public double[] Fs => line.Skip(idx++).Select(double.Parse).ToArray(); public decimal D => decimal.Parse(line[idx++]); public decimal[] Ds => line.Skip(idx++).Select(decimal.Parse).ToArray(); public BigInteger B => BigInteger.Parse(line[idx++]); public BigInteger[] Bs => line.Skip(idx++).Select(BigInteger.Parse).ToArray(); public void Write(params object[] xs) { Console.Write(xs.First()); foreach (var x in xs.Skip(1)) Console.Write(" " + x); Console.WriteLine(); } } static class Extentions { } static class Program { static void Main() { Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(new IO()); Console.Out.Flush(); } static void Solve(IO io) { io.R(); var t = io.I; for (var i = 0; i < t; i++) { var olds = Console.ReadLine(); var nonDigits = Enumerable.Range(32, 126) .Select(x => (char)x).Where(c => !char.IsDigit(c)).ToArray(); var oldsubs = olds.Split(nonDigits).LastOrDefault(s => s.Length > 0); if (oldsubs == null) { io.Write(olds); continue; } var idx = olds.LastIndexOf(oldsubs); var newsubs = Up(oldsubs); var news = olds.Remove(idx, oldsubs.Length).Insert(idx, newsubs); io.Write(news); } } static string Up(string str) { var sb = new StringBuilder(str); for (var i = str.Length - 1; i >= 0; i--) { if (sb[i] < '9') { var c = sb[i]; sb.Remove(i, 1).Insert(i, c - '0' + 1); break; } else { sb.Remove(i, 1).Insert(i, '0'); } } var len = str.Length - sb.Length; if (len > 0) sb.Insert(0, new string(Enumerable.Repeat('0', str.Length - sb.Length).ToArray())); if (str.All(c => c == '9')) sb.Insert(0, '1'); return sb.ToString(); } }