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; int n11 = 0; int n12 = 0; int n21 = 0; int n22 = 0; int n31 = 0; int n32 = 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) { n32 = s.length(); } else { n21 = j + 1; n12 = j + 1; break; } } else { if(p == 0) { a = 1; n31 = Math.max(n31, j + 1); n22 = Math.max(n22, j + 1); } else { s1 = str + s1; } } } if(n11 < n12) s1 = s.substring(n11, n12); if(n21 < n22) num = s.substring(n21, n22); if(n31 < n32) s2 = s.substring(n31, n32); 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); } } } }