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.ArrayList;
  import java.util.Arrays;
  import java.util.HashSet;
  import java.util.LinkedList;
  import java.util.Queue;
  import java.util.Scanner;
  import java.util.Set;
  import java.util.Stack;
  
  public class Codeforces {
  
  
  	static Scanner sc=new Scanner(System.in);
  
  	public static void main(String[] args) {
  		int t=1;
  		t=sc.nextInt();
  
  		while(t-->0) {
  			solve();
  
  		}
  
  	}
  
  	private static void fill(int[][] arr) {
  
  
  
  		/*int n=arr.length;
  
  		int count=1;
  		for(int i=0;i<n;i++) {
  			arr[i][i]=count++;
  		}
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<i;j++) {
  				arr[i][j]=count++;
  				arr[j][i]=count++;
  			}
  		}
  
  		/*
  		if(i>=n)
  			return true;
  
  		for(int k=1;k<=n*n;k++) {
  			if(!set.contains(k)) {
  				int count=0;
  				if(i-1>=0 && Math.abs(k-arr[i-1][j])==1) {
  					count++;
  				}
  				if(i+1<n && Math.abs(k-arr[i+1][j])==1) {
  					count++;
  				}
  				if(j-1>=0 && Math.abs(k-arr[i][j-1])==1) {
  					count++;
  				}
  				if(j+1<n && Math.abs(k-arr[i][j+1])==1) {
  					count++;
  				}
  				if(count==0) {
  					arr[i][j]=k;
  					//System.out.println(k);
  					set.add(k);
  					if(j==n-1) {
  						if(!fill(arr,i+1,0,set)) {
  							arr[i][j]=-5;
  							set.remove(k);
  						}else {
  							return true;
  						}
  					}else {
  						if(!fill(arr,i,j+1,set)) {
  							arr[i][j]=-5;
  							set.remove(k);
  						}else {
  							return true;
  						}
  					}
  
  				}
  
  			}
  		}
  		return false;
  		 */
  	}
  
  	private static void solve() {
  
  		int k=sc.nextInt();
  		
  		int n=1;
  		int i=1;
  		while(i<k) {
  			n++;
  			if(!(n%3==0 || n%10==3)) {
  				i++;
  			}
  		
  		}
  		
  		System.out.println(n);
  
  
  		/*int n=sc.nextInt();
  		int m=sc.nextInt();
  
  		String input[]=new String[n];
  
  		String out[]=new String[n-1];
  
  		for(int i=0;i<n;i++) {
  			input[i]=sc.next();
  		}
  
  		for(int i=0;i<n-1;i++) {
  			out[i]=sc.next();
  		}
  
  		int count1=0;
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<input[i].length();j++) {
  				count1+=input[i].charAt(j);
  			}
  		}
  
  		int count2=0;
  		for(int i=0;i<n-1;i++) {
  			for(int j=0;j<out[i].length();j++) {
  				count2+=out[i].charAt(j);
  			}
  		}
  
  		for(int i=0;i<n;i++) {
  			int count3=0;
  			for(int j=0;j<input[i].length();j++) {
  				count3+=input[i].charAt(j);
  			}
  			if(count3==count1-count2) {
  				System.out.println(input[i]);
  				return;
  			}
  		}
  
  
  
  		/*int k=sc.nextInt();
  		int n=sc.nextInt();
  		int m=sc.nextInt();
  
  		int arr1[]=new int[n];
  		int arr2[]=new int[m];
  
  		for(int i=0;i<n;i++) {
  			arr1[i]=sc.nextInt();
  		}
  		for(int j=0;j<m;j++) {
  			arr2[j]=sc.nextInt();
  		}
  		int i=0;
  		int j=0;
  		boolean turn=true;
  		int a=0;
  		int ans[]=new int[m+n];
  
  		while(i<n && j<m) {
  			if(arr1[i]==0) {
  				ans[a++]=arr1[i++];
  				k++;
  				continue;
  			}
  			if(arr2[j]==0) {
  				ans[a++]=arr2[j++];
  				k++;
  				continue;
  			}
  			if(arr1[i]<arr2[j]) {
  				if(arr1[i]>k) {
  					System.out.println(-1);
  					return;
  				}else {
  					ans[a++]=arr1[i++];
  				}
  			}else {
  				if(arr2[j]>k) {
  					System.out.println(-1);
  					return;
  				}else {
  					ans[a++]=arr2[j++];
  				}
  			}
  
  		}
  		while(i<n) {
  			if(arr1[i]==0) {
  				ans[a++]=arr1[i++];
  				k++;
  				continue;
  			}
  			if(arr1[i]>k) {
  				System.out.println(-1);
  				return;
  			}else {
  				ans[a++]=arr1[i++];
  			}
  		}
  
  		while(j<m) {
  			if(arr2[j]==0) {
  				ans[a++]=arr2[j++];
  				k++;
  				continue;
  			}
  			if(arr2[j]>k) {
  				System.out.println(-1);
  				return;
  			}else {
  				ans[a++]=arr2[j++];
  			}
  		}
  
  		for(i=0;i<m+n;i++) {
  			System.out.print(ans[i]+" ");
  		}
  		System.out.println();
  		/*int r=sc.nextInt();
  		int b=sc.nextInt();
  		int d=sc.nextInt();
  
  		int min=Math.min(r,b);
  
  		int red=(r+min-1)/min;
  		int blue=(b+min-1)/min;
  		if(Math.abs(red-blue)<=d) {
  			System.out.println("YES");
  		}else {
  			System.out.println("NO");
  		}
  
  
  		/*int n=sc.nextInt();
  		int m=sc.nextInt();
  		int k=sc.nextInt();
  
  		int tCost=(m-1)+(n-1)*m;
  
  		if(k==tCost) {
  			System.out.println("YES");
  		}else {
  			System.out.println("NO");
  		}
  
  		/*int n=sc.nextInt();
  		String s=sc.next().substring(0,n);
  		Set<Character> set=new HashSet<Character>();
  
  		set.add(s.charAt(0));
  		for(int i=1;i<s.length();i++) {
  			if(s.charAt(i)==s.charAt(i-1)) {
  				continue;
  			}
  			if(set.contains(s.charAt(i))) {
  				System.out.println("NO");
  				return;
  			}
  			set.add(s.charAt(i));
  		}
  		System.out.println("YES");
  
  		/*long n=sc.nextLong();
  		if(n<10) {
  			System.out.println(n);
  			return;
  		}
  
  		Queue<Long> q=new LinkedList<Long>();
  		for(long i=1;i<10;i++) {
  			q.add(i);
  		}
  		int count=0;
  		while(q.peek()<=n) {
  			count++;
  			long front=q.poll();
  			q.add(front*10+(front%10));
  		}
  		System.out.println(count);
  
  		/*int n=sc.nextInt();
  
  		if(n==1) {
  			System.out.println(1);
  			return ;
  		}
  		if(n==2) {
  			System.out.println(-1);
  			return;
  		}
  
  		int arr[][]=new int[n][n];
  		fill(arr);
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<n;j++) {
  				System.out.print(arr[i][j]+" ");
  			}
  			System.out.println();
  		}
  
  
  		/*
  		int a=sc.nextInt();
  		int b=sc.nextInt();
  
  		if(b==1) {
  			System.out.println("NO");
  			return;
  		}
  
  		long x=a;
  		long y= (1L*a*b);
  		long z=x+y;
  
  		System.out.println("YES");
  		System.out.println(x+" "+y+" "+z);
  
  		/*int n=sc.nextInt();
  		int t=sc.nextInt();
  		String s=sc.next().substring(0,n);
  
  		Stack<Integer> st=new Stack<Integer>();
  		for(int i=n-1;i>=0;i--) {
  			if(s.charAt(i)=='1') {
  				st.push(i);
  			}
  		}
  		Stack<Integer> left=new Stack<Integer>();
  		for(int i=0;i<n;i++) {
  			if(s.charAt(i)=='1') {
  				left.push(i);
  				st.pop();
  			}else {
  				if(st.isEmpty() && left.isEmpty()) {
  					System.out.println(s);
  					return;
  				}else if(left.isEmpty()) {
  					int rightO=st.peek();
  					if(rightO-i<=t) {
  						s=s.substring(0,i)+'1'+s.substring(i+1,n);
  					}
  				}else if(st.isEmpty()) {
  					int leftIndex=left.peek();
  					if(i-leftIndex<=t) {
  						s=s.substring(0,i)+'1'+s.substring(i+1,n);
  					}
  				}else {
  					int rightO=st.peek();
  					int leftIndex=left.peek();
  					if(i-leftIndex != rightO-i && (i-leftIndex<=t || rightO-i<=t )) {
  						s=s.substring(0,i)+'1'+s.substring(i+1,n);
  					}
  				}
  			}
  
  		}
  		System.out.println(s);
  
  
  		/*
  		int n=sc.nextInt();
  		int arr[]=new int[2*n];
  		for(int i=0;i<2*n;i++) {
  			arr[i]=sc.nextInt();
  		}
  		Arrays.sort(arr);
  		int i=0;
  		int j=n;
  		int arr2[]=new int[2*n];
  		int k=0;
  		while(k<2*n) {
  			if(k%2==0) {
  				arr2[k++]=arr[i++];
  			}else {
  				arr2[k++]=arr[j++];
  			}
  		}
  
  		for(i=0;i<2*n;i++) {
  			System.out.print(arr2[i]+" ");
  		}
  		System.out.println();
  
  
  
  
  		/*long n=sc.nextLong();
  
  		long ans=n;
  		int i=1;
  
  		for(;;i++) {
  			if((Math.pow(2,i)-1)>=n) {
  				break;
  			}
  		}
  		System.out.println((long)Math.pow(2,i-1)-1);
  
  
  		/*
  		//Binary Decimal
  
  		long l=sc.nextLong();
  		long max=0;
  		while(l>0) {
  			max=Math.max(max, l%10);
  			l/=10;
  		}
  		System.out.println(max);
  
  		/*
  		//B. Putting Plates
  
  		int m=sc.nextInt();
  		int n=sc.nextInt();
  
  		int arr[][]=new int[m][n];
  		for(int i=0;i<n;i++) {
  			if(i%2==0) {
  				arr[0][i]=1;
  				arr[m-1][i]=1;
  			}
  		}
  
  		for(int i=2;i<m-2;i++) {
  			if(i%2==0) {
  				arr[i][0]=1;
  				arr[i][n-1]=1;
  			}
  		}
  
  		for(int i=0;i<m;i++) {
  			for(int j=0;j<n;j++) {
  				System.out.print(arr[i][j]);
  			}
  			System.out.println();
  		}
  
  
  		/*
  		//Colour the flag 
  		int n=sc.nextInt();
  		int m=sc.nextInt();
  
  		char arr[][]=new char[n][m];
  
  		for(int i=0;i<n;i++) {
  			String s=sc.next();
  			for(int j=0;j<m;j++) {
  				arr[i][j]=s.charAt(j);
  			}
  		}
  
  		boolean isRed=false;
  		int row=0;
  		int col=0;
  		for(int i=0;i<n;i++) {
  			boolean get=false;
  			for(int j=0;j<m;j++) {
  				if(arr[i][j]=='R') {
  					isRed=true;
  					row=i;
  					col=j;
  					get=true;
  					break;
  				}
  				if(arr[i][j]=='W') {
  					row=i;
  					col=j;
  					get=true;
  					break;
  				}
  			}
  			if(get)
  				break;
  		}
  		char color;
  		char color1;
  		if(isRed) {
  			color='R';
  			color1='W';
  		}else {
  			color='W';
  			color1='R';
  		}
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<m;j++) {
  				if((i%2==row%2 && j%2==col%2) || (i%2!=row%2 && j%2!=col%2) ) {
  					if( !(arr[i][j]==color || arr[i][j]=='.')  ) {
  						System.out.println("NO");
  						return ;
  					}
  				}else {
  					if(arr[i][j]==color) {
  						System.out.println("NO");
  						return ;
  					}
  				}
  			}
  		}
  
  		System.out.println("YES");
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<m;j++) {
  				if((i%2==row%2 && j%2==col%2) || (i%2!=row%2 && j%2!=col%2) ) {
  					arr[i][j]=color;
  				}else {
  					arr[i][j]=color1;
  				}
  			}
  		}
  
  		for(int i=0;i<n;i++) {
  			for(int j=0;j<m;j++) {
  				System.out.print(arr[i][j]);
  			}
  			System.out.println();
  		}
  		 */
  	}
  
  
  
  	private static int __gcd(int i, int j) {
  		if(i%j==0) {
  			return j;
  		}
  
  		return __gcd(j, i%j );
  	}
  
  
  
  
  
  }
  