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: /**
   * @Created_by : Lucent868
   * @Date : 17-08-2021
   * @Time :  19:53
   */
  
  import java.util.*;
  import java.io.*;
  import java.math.*;
  
   public class A {
      static InputReader in;
      static PrintWriter out;
  
      public static void main(String args[]) {
          new Thread(null, new Runnable() {
              public void run() {
                  try {
                      solve();
                      out.flush();
                      out.close();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }, "1", 1 << 26).start();
      }
  
      public static void solve() {
          in = new InputReader(System.in);
          out = new PrintWriter(System.out);
  
          int t = in.nextInt();
  
          ArrayList<Integer> al = new ArrayList<>();
          int x = 0;
          while (al.size()<=1003)
          {
              x++;
              String y = String.valueOf(x);
              if(x%3 == 0 || y.charAt(y.length()-1)=='3')
              {
                  continue;
              }
              al.add(x);
  
          }
  
  
          while (t-->0)
          {
              int k = in.nextInt();
              out.println(al.get(k-1));
  
          }
  
      }
  
  
  
      static class InputReader {
          private final InputStream stream;
          private final byte[] buf = new byte[8192];
          private int curChar, numChars;
          private SpaceCharFilter filter;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          public int read() {
              if (numChars == -1) {
                  throw new InputMismatchException();
              }
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0) {
                      return -1;
                  }
              }
              return buf[curChar++];
          }
  
          public String nextLine() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isEndOfLine(c));
              return res.toString();
          }
  
          public String readString() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          public long nextLong() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              long res = 0;
              do {
                  if (c < '0' || c > '9') {
                      throw new InputMismatchException();
                  }
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public int nextInt() {
              int c = read();
              while (isSpaceChar(c)) {
                  c = read();
              }
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9') {
                      throw new InputMismatchException();
                  }
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public int[] nextIntArray(int n) {
              int[] arr = new int[n];
              for (int i = 0; i < n; i++) {
                  arr[i] = nextInt();
              }
              return arr;
          }
  
          public long[] nextLongArray(int n) {
              long[] arr = new long[n];
              for (int i = 0; i < n; i++) {
                  arr[i] = nextLong();
              }
              return arr;
          }
  
          public boolean isSpaceChar(int c) {
              if (filter != null)
                  return filter.isSpaceChar(c);
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          private boolean isEndOfLine(int c) {
              return c == '\n' || c == '\r' || c == -1;
          }
  
          public interface SpaceCharFilter {
              public boolean isSpaceChar(int ch);
          }
      }
  
      public static int[] sort(int[] arr) {
          List<Integer> temp = new ArrayList();
          for (int i : arr) temp.add(i);
          Collections.sort(temp);
          int start = 0;
          for (int i : temp) arr[start++] = i;
          return arr;
      }
  
      public static long[] sort(long[] arr) {
          List<Long> temp = new ArrayList();
          for (long i : arr) temp.add(i);
          Collections.sort(temp);
          int start = 0;
          for (long i : temp) arr[start++] = i;
          return arr;
      }
  
      public static int bs(int[] a, int fromIndex, int toIndex,
                           double key) {
          int low = fromIndex;
          int high = toIndex - 1;
  
          while (low <= high) {
              int mid = (low + high) >>> 1;
              long midVal = a[mid];
  
              if (midVal < key)
                  low = mid + 1;
              else if (midVal > key)
                  high = mid - 1;
              else
                  return mid; // key found
          }
          return -(low + 1);  // key not found.
      }
  
  }
  