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.io.*;
  import java.math.BigInteger;
  
      public class TestClass {
        private static  ArrayList<Integer> ans;
        public static int mod=(int)Math.pow(10,9)+7;
        public static void main(String[] args) {
          
          Scanner sc=new Scanner(System.in);
          int t=sc.nextInt();
          
         while(t-- > 0){
            
             int n = sc.nextInt();
             int count=1;
             int ans=1;
             while(count!=n){
                ans++;
                if(ans%3!=0 && ans%10!=3){
                   count++;
                }
             }
             System.out.println(ans);
  
             
        }
          
          
        }
        // ArrayList<Integer> adj[]=new ArrayList[n+2];
        //      for(int i=1;i<=n+1;i++){
        //        adj[i]=new ArrayList<>();
        //      }
        //      for(int i=1;i<=n-1;i++){
        //        adj[i].add(i+1);
        //      }
        //      for(int i=1;i<=n;i++){
        //        int temp=sc.nextInt();
        //        if(temp==0){
        //          adj[i].add(n+1);
        //        }else{
        //          adj[n+1].add(i);
        //        }
        //      }
        //      boolean visit[]=new boolean[n+2];
        //      ans=new ArrayList<>();
        //      boolean found=false;
        //      for(int i=1;i<=n+1;i++){
        //         ans.add(i);
        //         visit[i]=true;
        //         found=dfs(adj,visit,n,1);
        //         if(found)break;
        //         Arrays.fill(visit,false);
        //         ans.clear();
        //      }
            
        //      if(found){
        //          for(int e:ans){
        //            System.out.print(e+" ");
        //          }
        //          System.out.println();
        //      }
        //      else{
        //         System.out.println(-1);
        //      }
        // public static boolean dfs(ArrayList<Integer> adj[],boolean[] visit,int n,int cur){
        //    if(ans.size()==n+1){
        //      return true;
        //    }
        //    for(int e:adj[cur]){
        //     if(!visit[e]){
        //       ans.add(e);
        //       visit[e]=true;
        //       return dfs(adj,visit,n,e);
        //     }
        //    }
        //    return false;
        // }
        
        public static void backtrack(int n,ArrayList<Long> al,long xor,long and,int k){
          if(al.size()==n){
             //System.out.println(al+" "+xor+"   ");
             if(and>=xor){
              //System.out.println(al+"in");
              //ans =ans+1;
             }
             return;
          }
          for(long i=0;i<=(long)Math.pow(2,k)-1;i++){
             al.add(i);
             backtrack(n,al,xor^i,and&i,k);
             al.remove(al.size()-1);
          }
        }
        public static int findAlive(PriorityQueue<Integer> adj[],int n){
          int count=0;
           for(int i=1;i<=n;i++){
             if(adj[i].isEmpty())count++;
             else if(adj[i].peek()<i)count++;
           }
           return count;
        }
        public static long findMin(long n){
          if(n==0)return 0;
          if(n<=6)return 15;
          if(n<=8)return 20;
          if(n<=10)return 25;
          if(n<=12){
            return 30;
          }
          if(n<=16){
            return 40;
          }
          if(n<=20){
            return 50;
          }
          return (findMin(n%20)+(10)*25);
        }
        public static int  gcd(int a,int b){
          if(a==0){
            return b;
          }
          return gcd(b%a,a);
        }
        public static int removeZeros(int n){
              int res=0,pro=1;
              while(n>0){
              	int r=n%10;
              	if(r!=0){
              		res=res+r*pro;
              	    pro*=10;
              	}
              	n/=10;
              }
              //System.out.println(res);
              return res;
  
          }
  
      }
  