description: Polycarp doesn't like integers that are divisible by 3 or end with the digit 3 in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too.
  
  Polycarp starts to write out the positive (greater than 0) integers which he likes: 1, 2, 4, 5, 7, 8, 10, 11, 14, 16, .... Output the k-th element of this sequence (the elements are numbered from 1).
  
  Input
  
  The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow.
  
  Each test case consists of one line containing one integer k (1 ≤ k ≤ 1000).
  
  Output
  
  For each test case, output in a separate line one integer x — the k-th element of the sequence that was written out by Polycarp.
  
  Example
  
  Input
  
  
  10
  1
  2
  3
  4
  5
  6
  7
  8
  9
  1000
  
  
  Output
  
  
  1
  2
  4
  5
  7
  8
  10
  11
  14
  1666
solution: /*
      Date: 18-08-2021
      Time: 20:05
      Author: Kartik Papney
      Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/
      Leetcode: https://leetcode.com/kartikpapney/
      Codechef: https://www.codechef.com/users/kartikpapney
  */
  
  import java.util.*;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  
  public class Main {
      public static void solve() {
          int k = sc.nextInt();
          int val = 1;
          while (k != 1) {
              val++;
              if(!(val%3 == 0 || val%10 == 3)) k--;
          }
          p.writeln(val);
      }
  
      public static void main(String[] args) {
          int t = 1;
           t = sc.nextInt();
          while (t-- != 0) {
              solve();
          }
          p.print();
      }
  
  
      static final Integer MOD = (int) 1e9 + 7;
      static final FastReader sc = new FastReader();
      static final Print p = new Print();
  
      static class Functions {
  
          static void sort(int[] a) {
              ArrayList<Integer> l = new ArrayList<>();
              for (int i : a) l.add(i);
              Collections.sort(l);
              for (int i = 0; i < a.length; i++) a[i] = l.get(i);
          }
  
          static void sort(long[] a) {
              ArrayList<Long> l = new ArrayList<>();
              for (long i : a) l.add(i);
              Collections.sort(l);
              for (int i = 0; i < a.length; i++) a[i] = l.get(i);
          }
  
          static int max(int[] a) {
              int max = Integer.MIN_VALUE;
              for (int val : a) max = Math.max(val, max);
              return max;
          }
  
          static int min(int[] a) {
              int min = Integer.MAX_VALUE;
              for (int val : a) min = Math.min(val, min);
              return min;
          }
  
          static long min(long[] a) {
              long min = Long.MAX_VALUE;
              for (long val : a) min = Math.min(val, min);
              return min;
          }
  
          static long max(long[] a) {
              long max = Long.MIN_VALUE;
              for (long val : a) max = Math.max(val, max);
              return max;
          }
  
          static long sum(long[] a) {
              long sum = 0;
              for (long val : a) sum += val;
              return sum;
          }
  
          static int sum(int[] a) {
              int sum = 0;
              for (int val : a) sum += val;
              return sum;
          }
  
          public static long mod_add(long a, long b) {
              return (a % MOD + b % MOD + MOD) % MOD;
          }
  
          public static long pow(long a, long b) {
              long res = 1;
              while (b > 0) {
                  if ((b & 1) != 0)
                      res = mod_mul(res, a);
                  a = mod_mul(a, a);
                  b >>= 1;
              }
              return res;
          }
  
          public static long mod_mul(long a, long b) {
              long res = 0;
              a %= MOD;
              while (b > 0) {
                  if ((b & 1) > 0) {
                      res = mod_add(res, a);
                  }
                  a = (2 * a) % MOD;
                  b >>= 1;
              }
              return res;
          }
  
          public static long gcd(long a, long b) {
              if (a == 0) return b;
              return gcd(b % a, a);
          }
  
          public static long factorial(long n) {
              long res = 1;
              for (int i = 1; i <= n; i++) {
                  res = (i % MOD * res % MOD) % MOD;
              }
              return res;
          }
  
          public static int count(int[] arr, int x) {
              int count = 0;
              for (int val : arr) if (val == x) count++;
              return count;
          }
  
          public static ArrayList<Integer> generatePrimes(int n) {
              boolean[] primes = new boolean[n];
              for (int i = 2; i < primes.length; i++) primes[i] = true;
              for (int i = 2; i < primes.length; i++) {
                  if (primes[i]) {
                      for (int j = i * i; j < primes.length; j += i) {
                          primes[j] = false;
                      }
                  }
              }
              ArrayList<Integer> arr = new ArrayList<>();
              for (int i = 0; i < primes.length; i++) {
                  if (primes[i]) arr.add(i);
              }
              return arr;
          }
      }
  
      static class Print {
          StringBuffer strb = new StringBuffer();
  
          public void write(Object str) {
              strb.append(str);
          }
  
          public void writes(Object str) {
              strb.append(str).append(" ");
          }
  
          public void writeln(Object str) {
              strb.append(str).append("\n");
          }
  
          public void writeln() {
              strb.append('\n');
          }
  
          public void writes(int[] arr) {
              for (int val : arr) {
                  write(val);
                  write(' ');
              }
          }
  
          public void writes(long[] arr) {
              for (long val : arr) {
                  write(val);
                  write(' ');
              }
          }
  
          public void writeln(int[] arr) {
              for (int val : arr) {
                  writeln(val);
              }
          }
  
          public void print() {
              System.out.print(strb);
          }
  
          public void println() {
              System.out.println(strb);
          }
      }
  
      static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              br = new BufferedReader(new InputStreamReader(System.in));
          }
  
          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          int[] readArray(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) a[i] = nextInt();
              return a;
          }
  
          long[] readLongArray(int n) {
              long[] a = new long[n];
              for (int i = 0; i < n; i++) a[i] = nextLong();
              return a;
          }
  
          double[] readArrayDouble(int n) {
              double[] a = new double[n];
              for (int i = 0; i < n; i++) a[i] = nextInt();
              return a;
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
      }
  }
  