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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.Arrays;
  import java.util.StringTokenizer;
  import java.util.stream.Stream;
  import java.util.*;
  
  public class B{
  	
  	public static void main(String ar[]) throws IOException{
  
  		InputOutput io=new InputOutput();
  		int t=io.getInt();
  		while(t--!=0) {
  			int k=io.getInt();
  			int count=0;
  			while(k!=0) {
  				count++;
  				//System.out.print(count+" ");
  				if(count%3!=0 && count%10!=3) {
  					k--;
  				}
  			}
  			System.out.println(count);
  		}
  	}
  	
  	static class InputOutput{
  		static BufferedReader br;
  		static StringTokenizer token;
  		
  		InputOutput(){
  			br=new BufferedReader(new InputStreamReader(System.in));
  			token=new StringTokenizer("");
  		}
  		
  		static public int dist(int x,int y) {
  			return Math.abs(x-y);
  		}
  		
  		static public int binarySearch(int start,int end,int val,int arr[]) {
  			int mid=(start+end)/2;
  			if(arr[mid]==val) {
  				return mid;
  			}
  			else if(val>arr[mid]) {
  				return binarySearch(mid+1,end,val,arr);
  			}else{
  				return binarySearch(start,mid-1,val,arr);
  			}
  		}
  		
  		static public int getInt() throws IOException{
  			if(!token.hasMoreTokens())
  				token=new StringTokenizer(br.readLine());
  			return Integer.parseInt(token.nextToken());
  		}
  		
  		static public int[] getIntArray(int n) throws IOException{
  			token=new StringTokenizer(br.readLine());
  			int arr[]=new int[n];
  			for(int i=0;i<n;i++)
  				arr[i]=Integer.parseInt(token.nextToken());
  			return arr;
  //			return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  		}
  		
  		static public int[] getIntArray(int size,int value) throws IOException{
  			int arr[]=new int[size];
  			Arrays.fill(arr, value);
  			return arr;
  		}
  
  		static public int hcf(int a,int b) {
  			return (a%b==0) ? b : hcf(b,a%b);
  		}
  		
  		static public long lcm(int a,int b) {
  			return ((long)a*b)/hcf(a,b);
  		}
  		
  	}
  }