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.util.*;
  //import java.util.Stack;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.Map;
  import java.util.PriorityQueue;
  import java.util.Queue;
  import java.util.SortedSet;
  import java.util.Stack;
  import java.util.StringTokenizer;
  import java.util.TreeMap;
  import java.util.TreeSet;
  import java.io.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.PrintWriter;
  import java.io.BufferedWriter;
  import java.io.Writer;
  import java.io.OutputStreamWriter;
  import java.util.InputMismatchException;
  import java.io.IOException;
  import java.io.InputStream;
  public class Main {
  
  
      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());
          }
          String nextLine()
          {
              String str = "";
              try
              {
                  str = br.readLine();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
      public static int gcd(int a, int b)
      {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
  
       static class obj{
             int a1;
             int a2;
             obj(int a1,int a2){
                 this.a1=a1;
                 this.a2=a2;
             }
         }
         static  class sortby implements Comparator<obj>{
             public   int compare(obj o1,obj o2){
                 return o1.a1>o2.a1?1:-1;
             }
         }
      static int LowerBound(int a[], int x) { // x is the target value or key
          int l=-1,r=a.length;
          while(l+1<r) {
              int m=(l+r)>>>1;
              if(a[m]>=x) r=m;
              else l=m;
          }
          return r;
      }
      static int UpperBound(int a[], int x) {// x is the key or target value
          int l=-1,r=a.length;
          while(l+1<r) {
              int m=(l+r)>>>1;
              if(a[m]<=x) l=m;
              else r=m;
          }
          return l+1;
      }
  
      public static void main(String[] args) {
          FastReader s = new FastReader();
          //InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          PrintWriter out = new PrintWriter(outputStream);
          //Scanner s=new Scanner(System.in);
          int t = s.nextInt();
          while (t-- > 0) {
              int n = s.nextInt();
                int k=n/9;
              int c=1;
                while(n>0){
                    if(c%10==3||c%3==0){
                        c++;
                    }
                    else{
                        c++;
                    n--;}
                }
                c=c-1;
                out.println(c);
  
                      }
          out.close();
      }
  }
  