import java.io.*; import java.util.*; public class Main_yukicoder362 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int t = sc.nextInt(); long[][] dp = new long[14][100]; Arrays.fill(dp[0], 1L); for (int i = 1; i < 14; i++) { for (int k = 0; k < 100; k++) { for (int l = 0; l < 100; l++) { if (isKado(k, l)) { dp[i][k] += dp[i - 1][l]; } } } } for (int tcase = 0; tcase < t; tcase++) { long k = sc.nextLong(); List ans = new ArrayList<>(); long sum = 0; out: for (int i = 1; i < 14; i++) { for (int j = 10; j < 100; j++) { if (sum + dp[i][j] >= k) { k -= sum; ans.add(j); for (int ii = i - 1; ii >= 0; ii--) { int prev = ans.get(ans.size() - 1); for (int jj = 0; jj < 100; jj++) { if (isKado(prev, jj)) { if (k - dp[ii][jj] <= 0) { ans.add(jj); break; } else { k -= dp[ii][jj]; } } } } // pr.println(j); break out; } sum += dp[i][j]; } } StringBuilder s = new StringBuilder(); for (int i = 0; i < ans.size(); i++) { if (i == ans.size() - 1) { s.append(String.format("%02d", ans.get(i))); } else { s.append(ans.get(i) / 10); } } pr.println(s); } pr.close(); sc.close(); } private static boolean isKado(int a, int b) { int a1 = a / 10; int a2 = a % 10; int b1 = b / 10; int b2 = b % 10; if (a2 != b1 || a1 == a2 || b1 == b2 || a1 == b2) { return false; } if (a1 > a2 && a2 > b2) { return false; } if (a1 < a2 && a2 < b2) { return false; } return true; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }