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.InputStreamReader;
  import java.util.*;
  public class Main{
      static int mod=(int)1e9+9;
      static boolean isPerfectSquare(long x)
      {
          if (x >= 0) {
             
              // Find floating point value of
              // square root of x.
              long sr = (long)Math.sqrt(x);
             
              // if product of square root
              // is equal, then
              // return T/F
   
              return ((sr * sr) == x);
          }
          return false;
      }
         public static void main(String args[]){
                FastScanner in=new FastScanner();
                int test=in.nextInt();
                while(test-->0){
                    int k=in.nextInt();
                    int count=1;
      int val=0;
      int val1=0;
      while(val<k){
          String s=String.valueOf(count);
          if(count%3==0 || s.charAt(s.length()-1)=='3'){++count;++val1;continue;}
          ++count;
          ++val;
      }
      System.out.println(val+val1);
                }
                }
         public static void dfs(int node,ArrayList<Pair> arr[],boolean visited[],boolean problem,ArrayList<Integer> list){
             visited[node]=true;
             boolean flag=false;
             for(Pair i:arr[node]){
                 if(!visited[i.x]){
                     flag=true;
                     dfs(i.x,arr,visited,(i.y==2?true:false || problem),list);
                 }
             }
             if(!flag && node!=0)
                 list.add(node);
             
         }
         public static void factor(long n,HashSet<Long> set){
             for(long i=2;i*i<=n;i++){
                 if(n%i==0){
                     set.add(i);
                     while(n%i==0){
                         n=n/i;
                     }
                 }
             }
             if(n!=0 && n!=1)
                 set.add(n);
         }
         public static int bakchodi(int arr[],int dp[][],int n,int turn,int index){
             if(index>=n)
                 return 0;
             
             if(dp[index][turn]!=-1)
                 return dp[index][turn];
             
             int ans1=Integer.MAX_VALUE;
             int ans2=Integer.MAX_VALUE;
             if(turn==0){
                 if(index<n)
                     ans1=arr[index]+bakchodi(arr,dp,n,1-turn,index+1);
                 
                 if(index+1<n)
                     ans2=arr[index]+arr[index+1]+bakchodi(arr,dp,n,1-turn,index+2);
             }
             else{
                 ans1=bakchodi(arr,dp,n,1-turn,index+1);
                 ans2=bakchodi(arr,dp,n,1-turn,index+2);
             }
              return dp[index][turn]=Math.min(ans1,ans2);
         }
         public static int rec1(int arr[],int turn,int index,int n){
             int ans1=0;
             int ans2=0;
             if(index>=n)
                 return 0;
             
             if(turn==0){
                 if(index<n)
                 ans1=arr[index]+rec1(arr,1-turn,index+1,n);
                 
                 if(index+1<n)
                     ans2=arr[index]+arr[index+1]+rec1(arr,1-turn,index+2,n);
             }
             else{
                 ans1=rec1(arr,1-turn,index+1,n);
                 ans2=rec1(arr,1-turn,index+2,n);
             }
             return Math.min(ans1,ans2);
         }
         public static int rec(int arr[][],int i,int j,int n){
             int sum=0;
             sum+=arr[i][j];
             
             int max=0;
            for(int k=j+1;k<n;k++)
                max=Math.max(max,rec(arr,1-i,k,n));
            
            sum+=max;
            
            return sum;
         }
        
         public static void rec(int i,int n,int count){
             if(i==n){
                 count++;
                 return;
             }
             if(i>n)
                 return;
             
             rec(i+1,n,count);
             rec(i+2,n,count);
         }
         public static long lcm(long x, long y) {
          return ((x * y) / gcd(x, y));
      }
         public static long gcd(long a,long b){
             if(a==0)
                 return b;
             
             return gcd(b%a,a);
         }
         public static int bakloli(char ch[],char c,int k){
             int n=ch.length;
             int k1=0;
             int i=0;
             int j=0;
             int ans=0;
             while(i<n){
                 if(j>=n)
                     break;
                 while(j<n && (ch[j]==c || k1<k)){
                     if(ch[j]!=c){
                         k1++;
                         
                     }
                     j++;
                 }
                 ans=Math.max(j-i,ans);
                 if(ch[i]!=c)
                     k1--;
                 
                 i++;
             }
             return ans;
         }
         
         public static long power(long a,long b){
            long ans=1;
            while(b > 0) {
      		if((b&1) == 1) ans = (ans*a) % mod;
      		a = (a*a) % mod;
      		b >>= 1;
      	}
            return ans;
         }
         public static int largestfactor(int n){
            
             for(int i=2;i*i<=n;i++){
                 if(n%i==0)
                     return n/i;
             }
             return 1;
         }
        
         public static int bs(int ele,int n,int arr[]){
             int low=0;
             int high=n-1;
             while(low<=high){
                 int mid=(low+high)/2;
                 if(arr[mid]>=ele){
                     low=mid+1;
                 }
                 else
                     high=mid-1;
             }
             return low;
         }
         private static int mergeAndCount(long[] arr, int l,
                                       int m, int r)
      {
   
          // Left subarray
          long[] left = Arrays.copyOfRange(arr, l, m + 1);
   
          // Right subarray
          long[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
   
          int i = 0, j = 0, k = l, swaps = 0;
   
          while (i < left.length && j < right.length) {
              if (left[i] <= right[j])
                  arr[k++] = left[i++];
              else {
                  arr[k++] = right[j++];
                  swaps += (m + 1) - (l + i);
              }
          }
          while (i < left.length)
              arr[k++] = left[i++];
          while (j < right.length)
              arr[k++] = right[j++];
          return swaps;
      }
   
      // Merge sort function
      private static int mergeSortAndCount(long[] arr, int l,
                                           int r)
      {
   
          // Keeps track of the inversion count at a
          // particular node of the recursion tree
          int count = 0;
   
          if (l < r) {
              int m = (l + r) / 2;
   
              // Total inversion count = left subarray count
              // + right subarray count + merge count
   
              // Left subarray count
              count += mergeSortAndCount(arr, l, m);
   
              // Right subarray count
              count += mergeSortAndCount(arr, m + 1, r);
   
              // Merge count
              count += mergeAndCount(arr, l, m, r);
          }
   
          return count;
      }
  }
  class FastScanner {
  		java.io.BufferedReader br = new java.io.BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st = new StringTokenizer("");
   
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			return st.nextToken();
  		}
   
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
   
  		int[] readArray(int n) {
  			int[] a = new int[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextInt();
  			return a;
  		}
   
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
  class Pair{
      int x;
      int y;
      Pair(int x,int y){
          this.x=x;
          this.y=y;
      }
  }
  class Sorting implements Comparator<Pair>{
      public int compare(Pair p1,Pair p2){
         
          return (int)(p2.x-p1.x);
      }
  }