import java.util.*; import java.math.BigDecimal; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); String line = sc.nextLine(); for(int i = 0; i < T; i++) { String s = sc.nextLine(); String s1 = ""; String s2 = ""; String num = ""; int p = 0; int a = 0; for(int j = s.length() - 1; j >= 0; j--) { String str = String.valueOf(s.charAt(j)); int t = -1; try { t = Integer.parseInt(str); } catch(NumberFormatException e) { } if(t == -1) { if(a == 1) p = 1; if(p == 0) { s2 = str + s2; } else { s1 = str + s1; } } else { if(p == 0) { a = 1; num = str + num; } else { s1 = str + s1; } } } if(!(num.equals(""))) { BigDecimal d = new BigDecimal(num); d = d.add(new BigDecimal(1)); String ds = d.toString(); int len = ds.length(); for(int j = 0; j < num.length() - len; j++) { ds = "0" + ds; } System.out.println(s1 + ds + s2); } else { System.out.println(s1 + s2); } } } }