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: import java.io.IOException;
  import java.io.InputStream;
  
  public class Main {
      static class FastReader {
          byte[] buf = new byte[2048];
          int index, total;
          InputStream in;
  
          FastReader(InputStream is) {
              in = is;
          }
  
          int scan() throws IOException {
              if (index >= total) {
                  index = 0;
                  total = in.read(buf);
                  if (total <= 0) {
                      return -1;
                  }
              }
              return buf[index++];
          }
  
          String next() throws IOException {
              int c;
              for (c = scan(); c <= 32; c = scan())
                  ;
              StringBuilder sb = new StringBuilder();
              for (; c > 32; c = scan()) {
                  sb.append((char) c);
              }
              return sb.toString();
          }
  
          String nextLine() throws IOException {
              int c;
              for (c = scan(); c <= 32; c = scan())
                  ;
              StringBuilder sb = new StringBuilder();
              for (; c != 10 && c != 13; c = scan()) {
                  sb.append((char) c);
              }
              return sb.toString();
          }
  
          char nextChar() throws IOException {
              int c;
              for (c = scan(); c <= 32; c = scan())
                  ;
              return (char) c;
          }
  
          int nextInt() throws IOException {
              int c, val = 0;
              for (c = scan(); c <= 32; c = scan())
                  ;
              boolean neg = c == '-';
              if (c == '-' || c == '+') {
                  c = scan();
              }
              for (; c >= '0' && c <= '9'; c = scan()) {
                  val = (val << 3) + (val << 1) + (c & 15);
              }
              return neg ? -val : val;
          }
  
          long nextLong() throws IOException {
              int c;
              long val = 0;
              for (c = scan(); c <= 32; c = scan())
                  ;
              boolean neg = c == '-';
              if (c == '-' || c == '+') {
                  c = scan();
              }
              for (; c >= '0' && c <= '9'; c = scan()) {
                  val = (val << 3) + (val << 1) + (c & 15);
              }
              return neg ? -val : val;
          }
  
      }
  
      static String solve(int[] arr,int n){
          StringBuilder sb=new StringBuilder();
          if(arr[1]==1){
              sb.append((n+1)+" ");
              for(int i=1;i<=n;i++)
                  sb.append(i+" ");
              return sb.toString();
          }else if(arr[n]==0){
              for(int i=1;i<=n;i++)
                  sb.append(i+" ");
              sb.append((n+1)+" ");
              return sb.toString();
  
          }else{
              boolean got=false;
              for(int i=1;i<=n;i++){
                  sb.append(i+" ");
                  if(!got && (i+1)<=n && arr[i]==0 && arr[i+1]==1){
                      got=true;
                      sb.append((n+1)+" ");
                  }
              }
              if(got)
                  return sb.toString();
              else
                  return "-1";
          }
  
  
  
  
      }
  
  
      public static void main(String[] args) throws  Exception {
          FastReader fs=new FastReader(System.in);
          int t=fs.nextInt();
          while(t-->0){
              int k=fs.nextInt();
              int i=1;
              int j=1;
              int count=0;
              while(count!=k){
  
                  if(i%3!=0 && i%10!=3){
                      count++;
                  }
                  i++;
  
  
  
              }
              System.out.println(i-1);
  
          }
  
  
  
      }
  }
  