import java.util.*; import java.io.*; class Solver { private String line; private int[] ans; private int[] tmp; private int min; public Solver(String line) { this.line = line; } public void solve() { ans = new int[6]; tmp = new int[6]; min = Integer.MAX_VALUE; solve(0); for(int i = 0; i < 6; i++) { System.out.print(ans[i]); } System.out.println(); } private void solve(int k) { if(k == 6) { int sum = 0; sum += Math.abs(tmp[0] - tmp[2]); sum += Math.abs(tmp[1] - tmp[2]); sum += Math.abs(tmp[2] - tmp[3]); sum += Math.abs(tmp[3] - tmp[4]); sum += Math.abs(tmp[2] - tmp[5]); if(sum < min) { System.arraycopy(tmp, 0, ans, 0, 6); min = sum; } } else { for(int i = 1; i <= 6; i++) { boolean flag = false; if(line.charAt(k) != 'x') { int value = line.charAt(k) - '0'; if(value != i) continue; } for(int j = 0; j < k; j++) { if(tmp[j] == i) { flag = true; } } if(!flag) { tmp[k] = i; solve(k + 1); tmp[k] = 0; } } } } } public class die_yuizumi { public static void main(String[] args) throws Exception { BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); while(n-- > 0) { Solver solver = new Solver(br.readLine()); solver.solve(); } } finally { if(br != null) br.close(); } } }