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, \dots$. Output the $k$-th element of this sequence (the elements are numbered from $1$).


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow.

Each test case consists of one line containing one integer $k$ ($1 \le k \le 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.


-----Examples-----

Input
10
1
2
3
4
5
6
7
8
9
1000
Output
1
2
4
5
7
8
10
11
14
1666


-----Note-----

None

Difficulty: EASY

Solutions:
arr = []
i = 0
while len(arr) <= 1000:
	for i in range(0, 2000):
		if i % 3 != 0 and i % 10 != 3:
			arr.append(i)
test_case = int(input())
for _ in range(test_case):
	n = int(input())
	print(arr[n - 1])


n = int(input())
lst = []
i = 1
while len(lst) < 1001:
	if i % 3 != 0 and i % 10 != 3:
		lst.append(i)
	i += 1
for i in range(n):
	test = int(input())
	print(lst[test - 1])


from sys import stdin
test = int(stdin.readline())
while test:
	arr = []
	n = int(stdin.readline())
	i = 1
	while len(arr) < n:
		if i % 3 != 0:
			if i % 10 != 3:
				arr.append(i)
		i += 1
	print(arr[-1])
	test -= 1


l = []
for i in range(1, 2001):
	if i % 3 != 0 and i % 10 != 3:
		l.append(i)
for _ in range(int(input())):
	n = int(input())
	print(l[n - 1])


for _ in range(int(input())):
	n = int(input())
	k = 0
	while n > 0:
		k += 1
		if k % 3 != 0 and k % 10 != 3:
			n -= 1
	print(k)


x = int(input())
l = [i for i in range(10000) if i % 3 != 0 and i % 10 != 3]
for i in range(x):
	z = int(input())
	print(l[z - 1])


A = []
B = ['hehehe']
for i in range(int(input())):
	A.append(int(input()))
x = 0
a = 1
while x < max(A):
	if str(a)[-1] != '3' and int(a) % 3 != 0:
		B.append(a)
		x += 1
	a += 1
for i in A:
	print(B[i])


arr = []
i = 0
while len(arr) < 1000:
	i += 1
	if i % 3 == 0 or i % 10 == 3:
		continue
	else:
		arr.append(i)
t = int(input())
for _ in range(t):
	print(arr[int(input()) - 1])


MAX_V = 1000

def read_data():
	n = int(input())
	values = []
	for _ in range(n):
		values.append(int(input()))
	return (n, values)

def main():
	(n, values) = read_data()
	polycarp_values = []
	current_value = 0
	for _ in range(MAX_V):
		while 1:
			current_value += 1
			if current_value % 3 == 0 or str(current_value)[-1] == '3':
				continue
			else:
				polycarp_values.append(current_value)
				break
	for v in values:
		print(polycarp_values[v - 1])
main()


for __ in range(int(input())):
	k = int(input())
	ans = 0
	while k:
		ans += 1
		if ans % 3 == 0 or ans % 10 == 3:
			continue
		k -= 1
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = 1
	arr = []
	while i < 3000:
		if i % 3 != 0 and i % 10 != 3:
			arr.append(i)
		i = i + 1
	print(arr[n - 1])


a = int(input())
s = []
for i in range(a):
	s.append(int(input()))
d = [i for i in range(1, max(s) * 2)]
del d[2::3]
z = 0
for elem in d:
	if elem % 10 == 3:
		del d[z]
	z += 1
for elem in s:
	print(d[elem - 1])


for _ in range(int(input())):
	k = int(input())
	l = []
	i = 1
	while len(l) < 1000:
		if i % 3 != 0 and i % 10 != 3:
			l.append(i)
		i += 1
	print(l[k - 1])


n = int(input())
l = 1
e = 1
sequence = []
while l <= 1000:
	if e % 3 != 0 and e % 10 != 3:
		sequence.append(e)
		l += 1
	e += 1
for i in range(n):
	k = int(input())
	print(sequence[k - 1])


a = int(input())
c = []
for y in range(1667):
	d = y % 10
	if y % 3 != 0 and d != 3:
		c.append(y)
for x in range(a):
	b = int(input())
	print(c[b - 1])


t = int(input())
arr = []
m = 2000
for j in range(1, m + 1):
	if j % 3 != 0 and j % 10 != 3:
		arr.append(j)
for i in range(t):
	k = int(input())
	print(arr[k - 1])


import sys
zz = not __debug__
if not zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = int(input())
arr = []
arr.append(0)
for i in range(10001):
	if i % 3 == 0 or str(i)[-1] == '3':
		continue
	else:
		arr.append(i)
for j in range(t):
	x = int(input())
	print(arr[x])


num = []
for i in range(1, 1667):
	if i % 3 != 0 and i % 10 != 3:
		num.append(i)
for _ in range(int(input())):
	print(num[int(input()) - 1])


t = int(input())
a = [1]
for _ in range(t):
	k = int(input())
	if k <= len(a):
		print(a[k - 1])
	else:
		x = a[len(a) - 1]
		while len(a) < k:
			x += 1
			if x % 3 != 0 and x % 10 != 3:
				a.append(x)
		print(a[k - 1])


t = int(input())
mas = [1, 2, 4, 5, 7, 8, 10, 11, 14, 16]
count = 16
while len(mas) < 1000:
	count += 1
	if count % 10 != 3 and count % 3 != 0:
		mas.append(count)
for i in range(t):
	n = int(input())
	n -= 1
	print(mas[n])


def find_loc_dislike_3(loc):
	num = 0
	i = 0
	while i < loc:
		num += 1
		if num % 3 == 0:
			continue
		if num % 10 == 3:
			continue
		i += 1
	return num
t = int(input())
for _ in range(t):
	k = int(input())
	print(find_loc_dislike_3(k))


t = int(input())
indexes = [int(input()) for i in range(t)]
posld = [0]
current_num = 1
while len(posld) != max(indexes) + 1:
	if current_num % 3 == 0 or current_num % 10 == 3:
		pass
	else:
		posld.append(current_num)
	current_num += 1
for i in range(t):
	print(posld[indexes[i]])


a = []
for i in range(2000):
	if i % 3 == 0 or i % 10 == 3:
		pass
	else:
		a.append(i)
for _ in range(int(input())):
	n = int(input())
	print(a[n - 1])


l = []
l.append(0)
for i in range(1, 1000000):
	if i % 3 != 0 and i % 10 != 3:
		l.append(i)
for t in range(int(input())):
	k = int(input())
	print(l[k])


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(1, 2000):
		if i % 3 != 0 and i % 10 != 3:
			arr.append(i)
		if len(arr) >= 1001:
			break
	print(arr[n - 1], end='\n')


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def pre():
	arr = []
	start = 1
	while len(arr) < 10003:
		if start % 3 != 0 and str(start)[-1] != '3':
			arr.append(start)
		start += 1
	return arr

def solve(pre):
	n = takein()
	print(pre[n - 1])

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	arr = pre()
	t = takein()
	for tt in range(1, t + 1):
		solve(arr)
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takein():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takesr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def solution():
	for t in range(int(input())):
		k = int(input())
		ans = 0
		for i in range(1, k + 1):
			ans += 1
			while ans % 3 == 0 or ans % 10 == 3:
				ans += 1
		print(ans)
	return
solution()


arr = []
i = 0
while len(arr) <= 1000:
	i += 1
	if i % 3 == 0 or i % 10 == 3:
		continue
	else:
		arr.append(i)
n = int(input())
for j in range(n):
	x = int(input())
	print(arr[x - 1])


for i in range(int(input())):
	n = int(input())
	k = 1
	for i in range(1, n):
		k += 1
		if k % 3 == 0:
			k += 1
		if k % 10 == 3:
			k += 1
		if k % 3 == 0:
			k += 1
	print(k)


list1 = []
for i in range(1, 1700):
	if i % 3 != 0 and i % 10 != 3:
		list1.append(i)
t = int(input())
for i in range(t):
	n = int(input())
	print(list1[n - 1])


print(*map(lambda x: (x := int(x)) + int((x + (y := (int((z := (x / 18)) + 0.5) + int(z + 1 / 6))) - 1) / 2) + y, open(0).read().split()[1:]), sep='\n')


t = int(input())
a = [1]
s = []
for i in range(t):
	n = int(input()) - 1
	if n < len(a):
		s.append(a[n])
	else:
		j = len(a) - 1
		k = 1
		while len(a) <= n:
			if not ((a[j] + k) % 3 == 0 or [*str(a[j] + k)][-1] == '3'):
				a.append(a[j] + k)
			k += 1
		s.append(a[n])
for i in s:
	print(i)


ans = []
for i in range(0, 2000):
	if i % 3 == 0 or i % 10 == 3:
		continue
	else:
		ans.append(i)
t = int(input())
for i in range(0, t):
	n = int(input())
	print(ans[n - 1])


arr = []
for i in range(1, 2000):
	if i % 3 == 0 or i % 10 == 3:
		continue
	arr.append(i)
t = int(input())
for _ in range(t):
	k = int(input())
	print(arr[k - 1])


t = int(input())
c = []
for x in range(1, 1667):
	if x % 10 != 3 and x % 3 != 0:
		c.append(x)
for x in range(t):
	print(c[int(input()) - 1])


x = 0
n = 1
li = []
while x <= 1000:
	if n % 3 != 0 and n % 10 != 3:
		li.append(n)
		x += 1
	n += 1
t = int(input())
for j in range(t):
	k = int(input())
	print(li[k - 1])


numbers = []
for k in range(1, 2000):
	if str(k)[-1] == '3' or k % 3 == 0:
		pass
	else:
		numbers.append(k)
t = int(input())
K = []
for i in range(1, t + 1):
	k = int(input())
	K.append(k)
for k in K:
	print(numbers[k - 1])


test = int(input())
for i in range(test):
	val = int(input())
	num = 1
	while True:
		if num % 3 != 0 and num % 10 != 3:
			val -= 1
		if val == 0:
			print(num)
			break
		num += 1


lst = []
for i in range(1, 1667):
	if i % 3 != 0 and str(i)[-1] != '3':
		lst.append(i)
	else:
		pass
t = int(input())
for i in range(t):
	ele = int(input())
	print(lst[ele - 1])


count = 1
seq = []
for i in range(1000):
	if count % 3 == 0 or int(str(count)[-1]) == 3:
		count += 1
		if count % 3 == 0 or int(str(count)[-1]) == 3:
			count += 1
			seq.append(count)
		else:
			seq.append(count)
	else:
		seq.append(count)
	count += 1
for _ in range(int(input())):
	print(seq[int(input()) - 1])


t = int(input())
lst = []
for i in range(1, 2000):
	if i % 3 != 0 and i % 10 != 3:
		lst.append(i)
for i in range(t):
	n = int(input())
	print(lst[n - 1])


def chack(data):
	count = 0
	i = 0
	for i in range(10000):
		if i % 3 != 0 and i % 10 != 3:
			count += 1
		if count == data:
			return i
for _ in range(int(input())):
	k = int(input())
	x = chack(k)
	print(x)


a = int(input())
s = []
for i in range(a):
	b = int(input())
	s.append(b)
x = []
for i in range(1, 10000):
	if i % 10 != 3 and i % 3 != 0:
		x.append(i)
for i in s:
	print(x[i - 1])


x = []
a = 0
i = 1
while a <= 1000:
	if i % 3 != 0 and i % 10 != 3:
		a += 1
		x.append(i)
		i += 1
	else:
		i += 1
for _ in range(int(input())):
	n = int(input())
	print(x[n - 1])


def main() -> None:
	ans = []
	cur = 1
	while len(ans) != 1000:
		if cur % 3 != 0 and cur % 10 != 3:
			ans.append(cur)
		cur += 1
	for test in range(int(input())):
		k = int(input())
		print(ans[k - 1])
main()


a = []
for i in range(1, 1667):
	if i % 3 != 0 and i % 10 != 3:
		a.append(i)
t = int(input())
for i in range(t):
	n = int(input())
	print(a[n - 1])


T = int(input())
for t_itr in range(T):
	N = int(input())
	i = 1
	count = 1
	while count <= N:
		string = str(i)
		length = len(string)
		if i % 3 == 0 or string[length - 1] == '3':
			pass
		else:
			count += 1
		i += 1
	print(i - 1)


ser = []
for i in range(1, 4000):
	if i % 3 == 0 or i % 10 == 3:
		continue
	ser.append(i)
T = int(input())
for t in range(T):
	n = int(input())
	print(ser[n - 1])


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
MOD = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	li = []
	for i in range(2000):
		if i % 3 != 0 and str(i)[-1] != '3':
			li.append(i)
	for _ in range(int(input())):
		n = int(input())
		print(li[n - 1])
main()


from itertools import count, islice
t = int(input())
for _ in range(t):
	k = int(input())
	gen = (i for i in count(start=1) if i % 3 != 0 and i % 10 != 3)
	res = next(islice(gen, k - 1, None), None)
	print(res)


out = 1001 * [0]
i = 1
n = 1
while i <= 1000:
	out[i] = n
	n += 1
	while n % 3 == 0 or n % 10 == 3:
		n += 1
	i += 1
t = int(input())
for _ in range(t):
	print(out[int(input())])


ans = []
for n in range(50000):
	if n % 3 == 0 or str(n)[-1] == '3':
		continue
	ans.append(n)
t = input()
for _ in range(int(t)):
	k = int(input())
	print(ans[k - 1])


try:
	lis = []
	for i in range(5000):
		if i % 3 == 0 and str(i)[-1] == '3':
			pass
		elif i % 3 == 0:
			pass
		elif str(i)[-1] == '3':
			pass
		else:
			lis.append(i)
	t = int(input())
	for i in range(t):
		k = int(input())
		print(lis[k - 1])
except:
	pass


a = []
for i in range(1, 1667):
	if i % 3 != 0 and i % 10 != 3:
		a.append(i)
test = int(input())
for i in range(test):
	print(a[int(input()) - 1])


t = int(input())
l = []
for i in range(t):
	n = int(input())
	l.append(n)
m = max(l)
k = []
count = 0
j = 1
while count < m:
	p = list(str(j))
	if j % 3 != 0:
		if p[len(p) - 1] != '3':
			k.append(j)
			count += 1
	j += 1
for i in range(t):
	print(k[l[i] - 1])


from sys import stdin
input = lambda : stdin.readline().strip()
linput = lambda : [*map(int, input().split())]
output = []

def lprint(*x):
	output.append(' '.join(map(str, x)))
a = []
for i in range(1, 1000000):
	if len(a) > 1000:
		break
	if i % 3 and i % 10 != 3:
		a.append(i)

def main():
	lprint(a[int(input()) - 1])
for _ in ' ' * int(input()):
	main()
print(*output, sep='\n')


for s in [*open(0)][1:]:
	r = i = 0
	while i < int(s):
		r += 1
		i += r % 10 != 3 and r % 3 > 0
	print(r)


M = 5000
good_numbers = []
for i in range(1, M):
	if i % 3 == 0:
		pass
	elif i % 10 == 3:
		pass
	else:
		good_numbers.append(i)
t = int(input())
for i in range(t):
	k = int(input())
	print(good_numbers[k - 1])


import math
t = int(input())
l = list()
k = 1
i = 1
while k <= 1001:
	if i % 3 != 0 and i % 10 != 3:
		l.append(i)
		k = k + 1
	i = i + 1
while t > 0:
	a = int(input())
	print(l[a - 1])
	t = t - 1


def dislike():
	count = int(input())
	ip = []
	for x in range(count):
		ip.append(int(input()))
	series = []
	tmp = ''
	for i in range(1670):
		tmp = str(i)
		if i % 3 != 0 and int(tmp[-1]) != 3 and (i != 0):
			series.append(i)
	for k in ip:
		print(*series[k - 1:k], sep='\n')
dislike()


import math as M
import collections as C
import sys
IP = lambda : list(map(int, input().split()))
ip = lambda : input()
INF = sys.maxsize
MAX = 10 ** 9 + 7
ret = []
for i in range(1, INF):
	if len(ret) == 1000:
		break
	if i % 3 != 0 and i % 10 != 3:
		ret.append(i)
for _ in range(int(ip())):
	n = int(ip())
	print(ret[n - 1])


a = []
nt = int(input())
for i in range(nt):
	a.append(int(input()))
l = []
for i in range(1667):
	if i % 3 != 0 and str(i)[-1] != '3':
		l.append(i)
for i in a:
	print(l[i - 1])


a = []
for i in range(1, 1667):
	d = str(i)
	if len(d) == 1:
		if i % 3 != 0 and i != 3:
			a.append(i)
	elif i % 3 != 0 and d[len(d) - 1:] != '3':
		a.append(i)
t = int(input())
for i in range(t):
	k = int(input())
	print(a[k - 1])


t = int(input())
for _ in range(t):
	k = int(input())
	count = 0
	ans = 0
	while count < k:
		ans += 1
		if ans % 3 != 0 and int(str(ans)[-1]) != 3:
			count += 1
	print(ans)


t = int(input())
cases = []
counter = 1
n = 0
while t > 0:
	cases.append(int(input()))
	t -= 1
for case in cases:
	if case == 1:
		print(1)
	else:
		while counter <= case:
			n += 1
			if n % 3 != 0 and n.__str__()[-1] != '3':
				counter += 1
		print(n)
		counter = 1
		n = 0


def dislikeOfThrees():
	check = [x for x in range(1667) if x % 3 and str(x)[-1] != '3']
	n = int(input())
	for i in range(n):
		print(check[int(input()) - 1])
	return
dislikeOfThrees()


class Solution:

	def __init__(self):
		self.ans = []
		i = 0
		count = 1
		while i != 1003:
			if count % 3 != 0:
				if str(count)[-1] != '3':
					i += 1
					self.ans.append(count)
			count += 1

	def find(self):
		t = int(input())
		for i in range(t):
			x = int(input())
			print(self.ans[x - 1])
obj = Solution()
obj.find()


count = 0
li = []
for i in range(5000):
	if i % 3 != 0 and i % 10 != 3:
		count += 1
		li.append(i)
t = int(input())
for t in range(t):
	k = int(input())
	print(li[k - 1])


t = int(input())
for i in range(t):
	n = int(input())
	i = 0
	c = 1
	l = []
	while True:
		if c % 10 == 3 or c % 3 == 0:
			c += 1
		else:
			i += 1
			if i == n:
				print(c)
				break
			c += 1


x = int(input())
while x:
	k = int(input())
	j = 0
	a = 1
	res = 0
	while j < k:
		if a % 3 != 0 and a % 10 != 3:
			res = a
			j = j + 1
		a = a + 1
	print(res)
	x = x - 1


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
MOD = 1000000007
PI = 3.141592653589793
I = lambda : int(input())
S = lambda : input()
M = lambda : map(int, input().split())
Ms = lambda : map(str, input().split())
ARR = lambda : list(map(int, input().split()))
dp = []

def precalculate():

	def isValid(n):
		if n % 3 == 0 or n % 10 == 3:
			return False
		return True
	num = 1
	while len(dp) != 1000:
		if isValid(num):
			dp.append(num)
		num += 1

def solve():
	k = I()
	print(dp[k - 1])
precalculate()
tc = I()
for _ in range(tc):
	solve()


for _ in range(int(input())):
	n = int(input())
	i = 1
	while n > 1:
		i += 1
		if i % 10 == 3:
			i += 1
		if i % 3 == 0:
			i += 1
		if i % 10 == 3:
			i += 1
		n -= 1
	print(i)


def three(n):
	g = 1
	for i in range(2, n + 1):
		g += 1
		while g % 3 == 0 or g % 10 == 3:
			g += 1
	return g
t = int(input())
for i in range(t):
	k = int(input())
	print(three(k))


tot = int(input())
for i in range(tot):
	num = int(input())
	lst = []
	count = 0
	for i in range(3 * num):
		lst.append(str(i))
		i += 1
	for i in range(3 * num):
		if lst[i][len(lst[i]) - 1] == '3' or int(lst[i]) % 3 == 0:
			lst[i] = 0
	for i in range(3 * num):
		if lst[i] != 0:
			count += 1
		if count == num:
			print(i)
			break


t = int(input())
lst = []
k = 0
for j in range(1667):
	if j % 3 != 0 and j % 10 != 3:
		lst.append(j)
lst1 = []
for i in range(t):
	n = int(input())
	lst1.append(n)
for i in range(t):
	print(lst[lst1[i] - 1])


t = int(input())
needed = {}
count = 0
numbers = []
j = 0
for i in range(t):
	needed[i] = int(input())
while count < 1666:
	count += 1
	if count % 3 != 0 and count % 10 != 3:
		numbers.insert(j, count)
		j += 1
for value in needed.values():
	print(numbers[value - 1])


def seq_checker(n):
	if n % 3 != 0 and n % 10 != 3:
		return True
	else:
		False
ans_string = ''
t = int(input())
for i in range(t):
	k = int(input())
	loop_var = 1
	count = 0
	while True:
		if seq_checker(loop_var) == True:
			count += 1
		elif seq_checker(loop_var) == False:
			pass
		if count == k:
			ans = loop_var
			break
		loop_var += 1
	ans_string += str(ans) + '\n'
print(ans_string)


t = int(input())
for _ in range(t):
	n = int(input())
	num = 0
	while n:
		num += 1
		while num % 3 == 0 or str(num)[-1] == '3':
			num += 1
		n -= 1
	print(num)


from sys import flags, stdin
import math
import re
import queue
import typing
input = stdin.readline
MOD = 1000000007
INF = 122337203685477580

def solve_part():
	vec = []
	n = int(input().rstrip())
	for x in range(1, 2010):
		if str(x)[-1] != '3' and x % 3 != 0:
			vec.append(x)
	print(vec[n - 1])
	return

def solve():
	n = int(input().rstrip())
	for x in range(0, n):
		solve_part()
	return
solve()


def div3():
	div = []
	for i in range(1, 1700):
		if i % 3 != 0 and i % 10 != 3:
			div.append(i)
	return div
t = int(input())
div = div3()
for i in range(t):
	k = int(input())
	print(div[k - 1])


ans = []

def like(d):
	return d % 3 and d % 10 != 3
cur = 1
while len(ans) < 2000:
	if like(cur):
		ans.append(cur)
	cur += 1
for _ in range(int(input())):
	print(ans[int(input()) - 1])


import math, sys
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		dp = []
		i = 0
		for j in range(5000):
			i += 1
			if i % 10 == 3 or i % 3 == 0:
				continue
			dp.append(i)
		for k in range(I()):
			a = I()
			print(dp[a - 1])
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


for i in range(int(input())):
	n = int(input())
	k = list()
	for i in range(1, 3001):
		if i % 3 != 0 and i % 10 != 3:
			k.append(i)
	print(k[n - 1])


a = int(input())
b = 0
while b < a:
	c = int(input())
	d = 0
	f = []
	while d < 10000:
		e = 0
		if str(d)[-1] == '3':
			e = 1
		if d % 3 == 0:
			e = 1
		if e == 0:
			f.append(d)
		d = d + 1
	print(f[c - 1])
	b = b + 1


t = int(input())
for _ in range(t):
	n = int(input())
	(c, v) = (1, n)
	for i in range(1, 2 * n):
		if v == 0:
			break
		if i % 3 == 0 or i % 10 == 3:
			continue
		else:
			c = i
			v -= 1
	print(c)


test_case = int(input())
number = []
for j in range(0, test_case):
	num = int(input())
	number.append(num)
largest_number = max(number)
first_sequence = []
x = 1
for i in range(0, largest_number + 1):
	if x % 10 != 3 and x % 3 != 0:
		first_sequence.append(x)
		x += 1
	else:
		x += 1
		if x % 10 != 3 and x % 3 != 0:
			first_sequence.append(x)
			x += 1
		else:
			x += 1
			if x % 10 != 3 and x % 3 != 0:
				first_sequence.append(x)
				x += 1
for j in range(0, test_case):
	numbers = int(number[j] - 1)
	print(first_sequence[numbers])


test = input()
test = int(test)
l = []
for i in range(1, 1669):
	if i % 3 == 0 or i % 10 == 3:
		continue
	else:
		l.append(i)
for i in range(test):
	k = int(input())
	print(l[k - 1])


t = int(input())
for _ in range(t):
	k = int(input())
	num = 1
	l = []
	i = 0
	while i < k:
		if num % 3 == 0 or num % 10 == 3:
			num = num + 1
		else:
			l.append(num)
			num = num + 1
			i += 1
	print(l[-1])


t = int(input())
like_integers = []
for i in range(2000):
	if (i % 3 != 0) & (i % 10 != 3):
		like_integers.append(i)
for i in range(t):
	k = int(input())
	print(like_integers[k - 1])


import sys
input = sys.stdin.readline
memo = []
i = 1
while len(memo) < 1000:
	if i % 3 == 0 or str(i)[-1] == '3':
		i += 1
		continue
	memo.append(i)
	i += 1
T = int(input())
for _ in range(T):
	K = int(input())
	print(memo[K - 1])


t = int(input())
for _ in range(t):
	n = int(input())
	i = 1
	j = 1
	while i <= n:
		if j % 10 == 3 or j % 3 == 0:
			j += 1
		else:
			j += 1
			i += 1
	print(j - 1)


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations, accumulate, zip_longest, combinations_with_replacement
from math import gcd, floor, inf, log2, sqrt, log10, factorial
from bisect import bisect_right, bisect_left
from statistics import mode
from string import ascii_lowercase, ascii_uppercase
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, nlargest, nsmallest, merge
arr = []
for i in range(1, 2000):
	if i % 3 != 0 and i % 10 != 3:
		arr.append(i)
cases = int(input())
for _ in range(cases):
	num = int(input())
	print(arr[num - 1])


c = [1]
k = 1
n = int(input())
while len(c) != 2000:
	k += 1
	if k % 10 != 3 and k % 3 > 0:
		c.append(k)
for i in range(n):
	y = int(input())
	print(c[y - 1])


a = []
c = 1
while len(a) <= 1001:
	if c % 3 == 0 or c % 10 == 3:
		c += 1
	else:
		a.append(c)
		c += 1
for _ in range(int(input())):
	n = int(input())
	print(a[n - 1])


for i in range(int(input())):
	n = int(input())
	m = []
	for i in range(1, 3001):
		if i % 3 != 0 and i % 10 != 3:
			m.append(i)
	print(m[n - 1])


for i in range(int(input())):
	k = int(input())
	u = 0
	for j in range(1, 5000):
		if j % 3 != 0 and j % 10 != 3:
			u += 1
			if u == k:
				print(j)
				break


def func():
	a = []
	for i in range(10001):
		if i % 3 == 0 or i % 10 == 3:
			continue
		else:
			a.append(i)
	return a
l = []
l = func()
t = int(input())
for tt in range(t):
	x = int(input())
	print(l[x - 1])


l = [1]
for i in range(1, 1667):
	if i % 3 != 0 and i % 10 != 3:
		l.append(i)
a = int(input())
for j in range(a):
	j = int(input())
	print(l[j])


lst = []
for i in range(0, 100000):
	if i % 3 != 0 and i % 10 != 3:
		lst.append(i)
for _ in range(int(input())):
	n = int(input())
	print(lst[n - 1])


l = []
for i in range(1667):
	b = str(i)
	if i % 3 == 0 or b[-1] == '3':
		pass
	else:
		l.append(i)
for _ in range(int(input())):
	k = int(input())
	print(l[k - 1])


t = int(input())
m = []
ans = [1]
for y in range(t):
	m.append(int(input()))
count = 1
i = 1
while i != 1667:
	i += 1
	if i % 3 != 0:
		if i % 10 != 3:
			ans.append(i)
for x in m:
	print(ans[x - 1])


t = int(input())
k = []
for i in range(t):
	k.append(int(input()))
s = set(range(1, max(k) * 2))
s.difference_update(set(range(3, max(k) * 2, 3)))
s.difference_update(set(range(13, max(k) * 2, 10)))
s = list(s)
s.sort()
for c in k:
	print(s[c - 1])


l = []
t = 1
while len(l) != 1000:
	if list(str(t))[len(list(str(t))) - 1] != '3' and t % 3 != 0:
		l.append(t)
	t += 1
for _ in range(0, int(input())):
	a = int(input())
	print(l[a - 1])


def solve(n):
	likes = []
	i = 0
	num = 1
	while i < 1000:
		if num % 3 != 0 and str(num)[-1] != '3':
			likes.append(num)
			i += 1
		num += 1
	return likes[k - 1]
test_cases = int(input())
for _ in range(test_cases):
	k = int(input())
	print(solve(k))


t = int(input())
arr = []
for i in range(1, int(10000.0)):
	if len(arr) >= 1000:
		break
	if i % 3 == 0 or i % 10 == 3:
		continue
	else:
		arr.append(i)
for i in range(t):
	k = int(input())
	print(arr[k - 1])


kth = [0]
for i in range(1, 1667):
	if not (i % 3 == 0 or str(i)[-1] == '3'):
		kth.append(i)
t = int(input())
for i in range(t):
	k = int(input())
	print(kth[k])


count = 1
n = 1
number_holder = []
while count <= 1000:
	if n % 3 != 0 and n % 10 != 3:
		number_holder.append(n)
		count += 1
	n += 1
t = int(input(''))
for i in range(t):
	k = int(input(''))
	print(number_holder[k - 1])


t = int(input())
for i in range(0, t):
	ans = {}
	k = int(input())
	s = 1
	for j in range(1, 1670):
		if j % 3 == 0 or j % 10 == 3:
			continue
		else:
			ans[s] = j
		s = s + 1
	print(int(ans[k]))


arr = []
for i in range(1, 2500):
	x = str(i)
	b = 1
	if x[-1] == '3':
		b = 0
	if i % 3 == 0:
		b = 0
	if b == 1:
		arr.append(i)
t = int(input())
for i in range(t):
	n = int(input())
	print(arr[n - 1])


t = int(input())
numbers = []
i = 1
while len(numbers) < 1000:
	if i % 3 and i % 10 != 3:
		numbers.append(i)
	i += 1
for _ in range(t):
	k = int(input())
	print(numbers[k - 1])


polycrap = [i for i in range(1, 10001) if i % 10 != 3 and i % 3 != 0]
for _ in range(int(input())):
	k = int(input())
	print(polycrap[k - 1])


T = int(input())
arr = [None] * 1000
c = 0
i = 1
while c != 1000:
	if i % 3 == 0 or i % 10 == 3:
		i += 1
	else:
		arr[c] = i
		c += 1
		i += 1
for _ in range(T):
	k = int(input())
	print(arr[k - 1])


a = []
for i in range(1, 1667):
	if i % 3 == 0:
		continue
	elif i % 10 == 3:
		continue
	else:
		a += [i]
for _ in range(int(input())):
	n = int(input())
	print(a[n - 1])


k = int(input())
user_input = []
for i in range(k):
	user_input.append(int(input()))
user_max = max(user_input)
target_array = []
current_num = 0
for i in range(user_max):
	while True:
		current_num += 1
		if current_num % 3 != 0 and current_num % 10 != 3:
			target_array.append(current_num)
			break
for i in user_input:
	print(target_array[i - 1])


t = int(input())
l = []
for i in range(1, 1668):
	if i % 3 != 0 and i % 10 != 3:
		l.append(i)
for i in range(t):
	n = int(input())
	print(l[n - 1])


for q in range(int(input())):
	k = int(input())
	i = 0
	while k > 0:
		k -= 1
		i += 1
		while i % 3 == 0 or i % 10 == 3:
			i += 1
	print(i)


t = int(input())
l = []
for _ in range(t):
	l.append(int(input()))
m = max(l)
ans = []
i = 1
while len(ans) <= m:
	if i % 3 != 0 and i % 10 != 3:
		ans.append(i)
	i += 1
for i in l:
	print(ans[i - 1])


t = int(input())
for i in range(t):
	lis = []
	n = int(input())
	i = 1
	cnt = 1
	while cnt <= n:
		if i % 3 != 0 and i % 10 != 3:
			lis.append(i)
			cnt += 1
		i += 1
	print(lis[-1])


a = []
for i in range(1, 10000):
	if i % 3 == 0 or (i // 10 > 0 and i % 10 == 3):
		k = 1
	else:
		a.append(i)
t = int(input())
i = 0
for i in range(t):
	h = int(input())
	print(a[h - 1])


array = []
count = 0
i = 1
while count < 1000:
	while i % 3 == 0 or i % 10 == 3:
		i += 1
	array.append(i)
	i += 1
	count += 1
for _ in range(int(input())):
	n = int(input())
	print(array[n - 1])


t = int(input())
for q in range(t):
	k = int(input())
	l = [i for i in range(1, int(3 * (k + 1))) if i % 3 != 0 and i % 10 != 3]
	l.insert(1, 1)
	print(l[k])


lst = []
for i in range(1, 31):
	if i % 3 != 0 and str(i)[-1] != '3':
		lst.append(i)
t = int(input())
for _ in range(t):
	ith = int(input())
	if ith % 18 == 0:
		print((ith // 18 - 1) * 30 + lst[ith % 18 - 1])
	else:
		print(ith // 18 * 30 + lst[ith % 18 - 1])


t = int(input())
for tt in range(t):
	k = int(input())
	curr = 0
	counted = 0
	ans = 0
	while counted < k:
		curr += 1
		if curr % 3 and curr % 10 - 3:
			ans = curr
			counted += 1
	print(ans)


def init():
	for i in range(10000):
		if i % 3 != 0 and i % 10 != 3:
			a.append(i)

def solve():
	k = int(input())
	print(a[k - 1])
a = []
init()
t = int(input())
while t:
	t -= 1
	solve()


t = int(input())
while t:
	n = 0
	m = int(input())
	while m:
		n += 1
		s = str(n)
		if s[-1] == '3' or n % 3 == 0:
			continue
		m -= 1
	print(n)
	t -= 1


n = int(input())
for t in range(n):
	po = int(input())
	count = 0
	a = 0
	while count < po:
		if a % 3 != 0 and a % 10 != 3:
			count += 1
		a += 1
	print(a - 1)


for _ in range(int(input())):
	n = int(input())
	c = []
	for j in range(1, 1700):
		if not (j % 3 == 0 or j % 10 == 3):
			c.append(j)
	print(c[n - 1])


x = int(input())
i = 0
list1 = []
list2 = []
for p in range(1, 1700):
	if p % 3 == 0:
		pass
	elif p % 10 == 3:
		pass
	else:
		list2.append(p)
while i < x:
	n = int(input())
	list1.append(list2[n - 1])
	i += 1
for h in list1:
	print(h)


a = [i for i in range(1, 2000) if i % 3 != 0 and str(i)[-1] != '3']
for i in [*open(0)][1:]:
	print(a[int(i.strip()) - 1])


import math
import bisect
import copy
from collections import defaultdict
from collections import OrderedDict
from sys import stdout
import sys
for _ in range(int(input())):
	n = input()
	k = 0
	res = 0
	while k <= int(n):
		p = str(res)
		if p[-1] != '3' and res % 3 != 0:
			k += 1
		if k == int(n) and p[-1] != '3' and (res % 3 != 0):
			print(res)
			break
		res += 1


for _ in range(int(input())):
	n = int(input())
	a = []
	(cnt, i) = (1, 1)
	while cnt <= n:
		if i % 3 != 0 and i % 10 != 3:
			a.append(i)
			cnt += 1
		i += 1
	print(a[n - 1])


a = list(range(2000))
a = [x for x in a if x % 3 != 0 and x % 10 != 3]
n = int(input())
for _ in range(n):
	x = int(input())
	print(a[x - 1])


for _ in range(int(input())):
	k = int(input())
	c = 1
	while k > 0:
		if c % 3 != 0 and str(c)[-1] != '3':
			k -= 1
		if k > 0:
			c += 1
	print(c)


import os, sys, math
from io import BytesIO, IOBase
ip = lambda : input()
it = lambda : int(input())
ma = lambda : map(int, input().split(' '))
li = lambda : list(map(int, input().split(' ')))
mod = 10 ** 9 + 7

def main():
	a = []
	i = 1
	x = 0
	while x < 1000:
		if i % 3 == 0 or i % 10 == 3:
			i += 1
			continue
		a.append(i)
		i += 1
		x += 1
	for _ in range(int(input())):
		k = it()
		print(a[k - 1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(Answers, i) = ([], 0)
for x in range(1, 1001):
	if not (str(x + int(i)).endswith('3') and (x + int(i)) % 3):
		Answers.append(x + int(i))
		i += 0.5
	elif str(x + int(i)).endswith('3'):
		i += 1.5
		Answers.append(x + int(i))
		i += 0.5
Together = list(zip(range(1, 1001), Answers))
n = int(input())
while n > 0:
	inp = int(input())
	for (i, j) in Together:
		if inp == i:
			print(j)
			break
	n -= 1


n = int(input())
l = []
for i in range(n):
	l.append(int(input()))
mx = max(l)
ans = []
one = 1
ptr = 0
while ptr < mx:
	t = False
	while one % 3 == 0 or str(one)[-1] == '3':
		one += 1
		t = True
	if not t:
		ans.append(one)
		one += 1
		ptr += 1
for i in l:
	print(ans[i - 1])


tc = int(input())
for _ in range(tc):
	k = int(input())
	likes = []
	(i, cnt) = (1, 1)
	while cnt <= k:
		if i % 3 != 0 and i % 10 != 3:
			likes.append(i)
			cnt += 1
		i += 1
	print(likes[-1])


tests = int(input())
for i in range(tests):
	k = int(input())
	i = 0
	x = 1
	while True:
		if x % 3 != 0 and x % 10 != 3:
			i += 1
		if i == k:
			break
		x += 1
	print(x)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def intArr():
	return map(int, input().split())

def In():
	return int(input())

def func():
	global arr
	k = In()
	return arr[k - 1]

def main():
	for _ in range(In()):
		print(func())
	return
arr = []
for i in range(1, 10000):
	if i % 3 != 0 and i % 10 != 3:
		arr.append(i)
main()


X = 1
Kth = []
Kth.append(1)
while len(Kth) < 1010:
	if not (X % 3 == 0 or X % 10 == 3):
		Kth.append(X)
	X += 1
tC = int(input())
for __ in range(tC):
	K = int(input())
	print(Kth[K])


t = int(input())
arr = [i for i in range(0, 1667)]
ans = []
for i in range(0, len(arr)):
	c = str(arr[i])
	if arr[i] % 3 != 0 and c[len(c) - 1] != '3':
		ans.append(arr[i])
for _ in range(t):
	n = int(input())
	print(ans[n - 1])


t = int(input())
like_numbers = []
for x in range(1, 1667):
	if x % 3 != 0 and x % 100 % 10 != 3:
		like_numbers.append(x)
for test in range(t):
	test = int(input())
	print(like_numbers[test - 1])


t = int(input())
for i in range(t):
	list = []
	n = int(input())
	i = 1
	x = 1
	while x <= n:
		if i % 3 != 0 and i % 10 != 3:
			list.append(i)
			x = x + 1
		i = i + 1
	print(list[-1])


p = int(input())
for i in range(p):
	n = int(input())
	k = 0
	if n % 18 == 0:
		k = int(n / 18) - 1
	else:
		k = int(n / 18)
	k = k * 30
	r = n % 18
	val = [1, 2, 4, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22, 25, 26, 28, 29]
	print(k + val[r - 1])


from collections import defaultdict, deque
from itertools import permutations, combinations, product
from functools import lru_cache
from math import factorial

def pprint(E):
	for e in E:
		print(e)
from sys import setrecursionlimit, stdin
setrecursionlimit(500000)
readline = stdin.readline
INF = 10 ** 18
MOD = 1000000007
MOD2 = 998244353
cnt = ans = tmp = 0
(yes, no) = ('Yes', 'No')
yn = yes

def I():
	return int(readline())

def S():
	return readline()[:-1]

def LI():
	return list(map(int, readline().split()))

def SPI():
	return map(int, readline().split())

def FIE(x):
	return [readline()[:-1] for _ in [0] * x]

def ENU(x):
	return enumerate(x)

def NODE(x):
	return [[] for _ in [0] * (x + 1)]

def ZERO(x):
	return [0] * x

def ZEROS(y, x):
	return [[0] * x for _ in [0] * y]

def ZEROSS(z, y, x):
	return [[[0] * x for _ in [0] * y] for _ in [0] * z]
n = I()
M = []
for i in range(1, 2000):
	if i % 3 == 0:
		continue
	if str(i)[-1] == '3':
		continue
	M.append(i)
for _ in range(n):
	k = I()
	print(M[k - 1])


T = int(input())
count = 0
nr = 0
v = {}
while count < 1000:
	count += 1
	nr += 1
	if nr % 3 == 0 or nr % 10 == 3:
		nr += 1
	if nr % 3 == 0 or nr % 10 == 3:
		nr += 1
	v[count] = nr
for _ in range(T):
	x = int(input())
	print(v[x])


def dislike_three(k):
	(i, n, l) = (0, 0, 0)
	while n != k:
		i += 1
		if i % 3 and str(i)[-1] != '3':
			n += 1
			l = i
	return l
t = int(input())
for _ in range(t):
	k = int(input())
	print(dislike_three(k))


ls = [i for i in range(1, 1800) if i % 3 != 0 and str(i)[-1] != '3']
for _ in range(int(input())):
	n = int(input())
	print(ls[n - 1])


def search_numbers():
	solve = []
	cont = 0
	n = 1
	while cont <= 1000:
		if not (n % 3 == 0 or n % 10 == 3):
			cont += 1
			solve.append(n)
		n += 1
	return solve
numbers = search_numbers()
t = int(input())
for _ in range(t):
	k = int(input())
	print(numbers[k - 1])


import sys
import math
import bisect
t = int(input())
for a0 in range(t):
	n = int(input())
	c = 1
	k = 1
	while c <= n:
		if k % 3 == 0 or str(k)[-1] == '3':
			k += 1
		else:
			k += 1
			c += 1
	print(k - 1)


k = int(input())
for i in range(k):
	list = []
	a = int(input())
	i = 1
	count = 1
	while count <= a:
		if i % 3 != 0 and i % 10 != 3:
			list.append(i)
			count += 1
		i += 1
	print(list[-1])


tt = int(input())
l = [x for x in range(1700) if x % 3 != 0 and x % 10 != 3]
for _ in range(tt):
	n = int(input())
	print(l[n - 1])


ans = [0]
for i in range(1667):
	if i % 3 == 0 or i % 10 == 3:
		continue
	ans.append(i)
_t = int(input())
for _c in range(_t):
	n = int(input())
	print(ans[n])


l = []
for x in range(1, 2001):
	if x % 3 == 0 or x % 10 == 3:
		continue
	else:
		l.append(x)
for _ in range(int(input())):
	k = int(input())
	print(l[k - 1])


mass = [1]
for i in range(1, 10000):
	if i % 10 != 3 and i % 3 != 0:
		mass.append(i)
t = int(input())
for i in range(t):
	k = int(input())
	print(mass[k])


arr = []
for i in range(2000):
	if i % 10 != 3 and i % 3 != 0:
		arr.append(i)
for _ in range(int(input())):
	print(arr[int(input()) - 1])


n = int(input())
while n:
	m = int(input())
	c = 0
	for i in range(1, 2 * m + 1):
		if i % 3 != 0 and i % 10 != 3:
			c += 1
		if c == m:
			print(i)
			break
	n = n - 1


t = int(input())
for j in range(t):
	k = int(input())
	lyst = []
	for i in range(1, 1667):
		if i % 3 != 0 and i % 10 != 3:
			lyst.append(i)
	print(lyst[k - 1])


t = int(input())
i = []
while len(i) < 1000:
	for j in range(10000):
		if j % 3 != 0 and j % 10 != 3:
			i.append(j)
for _ in range(t):
	n = int(input())
	print(i[n - 1])


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	k = int(input())
	i = 1
	ans = 0
	start = 1
	while True:
		if str(start)[-1] != '3' and start % 3 != 0:
			if i == k:
				ans = start
				break
			else:
				i += 1
		start += 1
	print(ans)
print('\n'.join(ANS))


t = int(input())
lis1 = []
for i in range(t):
	a = int(input())
	lis1.append(a)
slis1 = sorted(lis1)
r = slis1[len(lis1) - 1]
newlis1 = []
counter = 0

def sumOfDigits(counter):
	s = 0
	for d in str(counter):
		s += int(d)
	return s
for i in range(r):
	counter += 1
	while counter % 10 == 3 or sumOfDigits(counter) % 3 == 0:
		counter += 1
	newlis1.append(counter)
for i in range(len(lis1)):
	print(newlis1[lis1[i] - 1])


t = int(input())
ans = []
ques = []
poss = []
for i in range(t):
	ques.append(int(input()))
m = max(ques)
I = 1
while I <= m * 2:
	if I % 3 != 0 and I % 10 != 3:
		poss.append(I)
	I += 1
for i in ques:
	print(poss[i - 1])


t = int(input())
m = []
while t != 0:
	k = int(input())
	x = 1
	while k != 0:
		if x % 3 != 0 and x % 10 != 3:
			m.append(x)
			k = k - 1
		x = x + 1
	print(m[-1])
	m.clear()
	t = t - 1


from sys import stdin
d = {}
c = 1
for i in range(1, 1001):
	d[i] = c
	c += 1
	if c % 3 == 0 or str(c)[len(str(c)) - 1] == '3':
		c += 1
	if c % 3 == 0 or str(c)[len(str(c)) - 1] == '3':
		c += 1
for _ in range(int(input())):
	n = int(stdin.readline())
	print(d[n])


lst = [0]
i = 1
while len(lst) <= 1000:
	if i % 3 != 0 and i % 10 != 3:
		lst.append(i)
	i += 1
t = int(input())
for i in range(t):
	n = int(input())
	print(lst[n])


from typing import DefaultDict
t = int(input())
ans = [0 for _ in range(t)]
mx = -1
s = set()
d = DefaultDict(list)
for i in range(t):
	k = int(input())
	d[k].append(i)
	if k > mx:
		mx = k
i = 1
c = 0
while c <= mx:
	if i % 3 != 0 and i % 10 != 3:
		c += 1
		if c in d:
			for idx in d[c]:
				ans[idx] = i
	i += 1
print('\n'.join(map(str, ans)))


t = int(input())
array = [0] * t
for i in range(t):
	array[i] = int(input())
maxarray = max(array)
result = [0]
now = 0
i = 0
while i <= maxarray:
	now += 1
	if now % 10 == 3 or now % 3 == 0:
		pass
	else:
		result.append(now)
		i += 1
for item in array:
	print(result[item])


import sys
import math
import heapq
from collections import defaultdict as dd
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)
T = int(input())
for _ in range(T):
	k = int(input())
	i = 1
	c = 0
	while c < k:
		if i % 3 == 0 or i % 10 == 3:
			i += 1
		else:
			i += 1
			c += 1
	print(i - 1)


def series():
	ls = []
	j = 0
	while len(ls) <= 1000:
		if j % 3 != 0 and j % 10 != 3:
			ls.append(j)
		j += 1
	return ls
n = int(input())
lst1 = []
for i in range(n):
	k = int(input())
	lst1.append(k)
lis = series()
for i in range(n):
	m = lis[lst1[i] - 1]
	print(m)


arr = [0]
j = 1
for i in range(1, 1667):
	if i % 3 != 0:
		if i % 10 != 3:
			arr.append(i)
for _ in range(int(input())):
	print(arr[int(input())])


t = int(input())
l = []
for _ in range(t):
	n = int(input())
	l.append(n)
r = [*range(max(l) * 2)]
r = [i for i in r if i % 3 != 0]
r = [i for i in r if i % 10 != 3]
for x in l:
	print(r[x - 1])


arr = [i for i in range(1, 1667) if i % 3 != 0 and i % 10 != 3]
for _ in range(int(input())):
	k = int(input())
	print(arr[k - 1])


a = [i for i in range(1700)]
b = []
for i in range(len(a)):
	if a[i] % 3 != 0 and a[i] % 10 != 3:
		b.append(a[i])
T = int(input())
for i in range(T):
	x = int(input())
	print(b[x - 1])


loop = int(input())
for i in range(loop):
	storage = []
	num = int(input())
	i = 1
	const = 1
	while const <= num:
		if i % 3 != 0 and i % 10 != 3:
			storage.append(int(i))
			const += 1
		i += 1
	print(storage[-1])


def solve():
	k = int(input())
	curr_num = 0
	num_written = 0
	while True:
		curr_num += 1
		if curr_num % 3 == 0 or curr_num % 10 == 3:
			continue
		else:
			num_written += 1
		if num_written == k:
			break
	print(curr_num)
for _ in range(int(input())):
	solve()


n = int(input())
query = []
max_query = 0
for _ in range(n):
	q = int(input())
	query.append(q)
	if q > max_query:
		max_query = q

def is_dislike(x):
	return (x % 3 == 0) | (str(x)[-1] == '3')
length = 1
cur = 0
arr = [0] + [None] * max_query
while True:
	if not is_dislike(cur):
		arr[length] = cur
		length += 1
	cur += 1
	if length == max_query + 1:
		break
for i in query:
	print(arr[i])


lis = []
for i in range(1, 2000):
	if i % 3 != 0 and str(i)[-1] != '3':
		lis.append(i)
for _ in range(int(input())):
	x = int(input())
	print(lis[x - 1])


for _ in range(int(input())):
	K = int(input())
	i = 1
	out = 0
	while out < K:
		if i % 3 == 0 or i % 10 == 3:
			i += 1
			continue
		out += 1
		if out == K:
			break
		i += 1
	print(i)


def seq():
	res = []
	for i in range(1, 2000):
		if i % 3 != 0 and str(i)[-1] != '3':
			res.append(i)
	return res

def main():
	res = seq()
	t = int(input())
	for _ in range(t):
		k = int(input())
		print(res[k - 1])
main()


def find(a):
	maxi = max(a)
	p = [0] * (maxi + 1)
	j = 1
	i = 1
	while i < maxi + 1:
		if j % 10 == 3 or j % 3 == 0:
			j += 1
		else:
			p[i] = j
			i += 1
			j += 1
	return p
t = int(input())
a = []
for i in range(t):
	a.append(int(input()))
p = find(a)
for i in a:
	print(p[i])


arr = [0 for i in range(1001)]
count = 0
n = 1

def ok(n):
	if n % 10 == 3:
		return False
	if n % 3 == 0:
		return False
	return True
while count < 1000:
	if ok(n):
		arr[count] = n
		count += 1
	n += 1
t = int(input())
for _ in range(t):
	k = int(input())
	print(arr[k - 1])


x = 1
i = 0
List = []
while True:
	if x % 3 == 0:
		x += 1
		continue
	elif x % 10 == 3:
		x += 1
		continue
	elif x % 3 == 0 and x % 10 == 0:
		x += 1
		continue
	else:
		List.append(x)
		i += 1
		x += 1
	if i == 1000:
		break
test = int(input())
while test:
	k = int(input())
	print(List[k - 1])
	test -= 1


t = int(input())
for i in range(t):
	k = int(input())
	c1 = 0
	current_num = 3
	j = 2
	if k < 3:
		print(k)
		continue
	while j < k:
		if c1 % 10 != 0 and current_num % 3 != 0:
			j += 1
		current_num += 1
		c1 += 1
	print(current_num - 1)


t = int(input())
for k in range(t):
	number = int(input())
	res = []
	i = 1
	while len(res) < number:
		if i % 3 != 0 and str(i)[-1] != '3':
			res.append(i)
		i += 1
	print(res[number - 1])


t = int(input())
for u in range(t):
	k = int(input())
	n = 0
	count = 0
	while count < k:
		n = n + 1
		if n % 3 != 0 and n % 10 != 3:
			count = count + 1
	print(n)


t = int(input())
for i in range(t):
	k = int(input())
	(c, d) = (1, 0)
	while d < k:
		if c % 3 != 0 and c % 10 != 3:
			d += 1
			if d == k:
				break
		c += 1
	print(c)


t = int(input())
b = []
l = 1
for i in range(t):
	k = int(input())
	while k > len(b):
		if l % 3 != 0 and l % 10 != 3:
			b.append(l)
		l += 1
	print(b[k - 1])


t = int(input())
r = []
for i in range(t):
	r.append(int(input()))
for i in range(t):
	ch = 1
	zn = 1
	while ch != r[i]:
		zn += 1
		if zn % 3 != 0 and zn % 10 != 3:
			ch += 1
	print(zn)


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
s = []
strt = 1
while len(s) < 1100:
	if strt % 3 != 0 and str(strt)[-1] != '3':
		s.append(strt)
	strt += 1
for _ in range(inp()):
	n = inp()
	print(s[n - 1])


arr = []
n = 1
while len(arr) != 1000:
	if not (n % 3 == 0 or n % 10 == 3):
		arr.append(n)
	n += 1
for i in range(int(input())):
	j = int(input())
	print(arr[j - 1])


t = int(input())
numarr = []
for n in range(5000):
	if n % 3 == 0:
		pass
	elif str(n)[-1] == '3':
		pass
	else:
		numarr += [n]
for _ in range(t):
	x = int(input())
	print(numarr[x - 1])


arr = list(range(1, 1667))
for i in arr:
	if str(i)[-1] == '3':
		arr.remove(i)
for i in arr:
	if i % 3 == 0:
		arr.remove(i)
re = []
a = int(input())
for i in range(a):
	temp = int(input())
	re.append(arr[temp - 1])
for i in re:
	print(i)


ref = []
cur = 1
for _ in range(1000):
	while cur % 10 == 3 or not cur % 3:
		cur += 1
	ref.append(cur)
	cur += 1
for _ in range(int(input())):
	print(ref[int(input()) - 1])


t = int(input())
cache = []
for x in range(1, 10001):
	if x % 3 == 0 or str(x)[-1] == '3':
		continue
	cache.append(x)
for _ in range(t):
	print(cache[int(input()) - 1])


from typing import List

def create_array(length: int=1000) -> List[int]:
	array = []
	num = 1
	while len(array) < length:
		if not (num % 3 == 0 or str(num)[-1] == '3'):
			array.append(num)
		num += 1
	return array

def main():
	array = create_array()
	t = int(input())
	for _ in range(t):
		k = int(input())
		print(array[k - 1])
main()


n = int(input())
list1 = []
list2 = []
for i in range(n):
	num = int(input())
	list1.append(num)
for j in range(1700):
	strj = str(j)
	if j % 3 == 0 or [*strj][-1] == '3':
		pass
	elif j % 3 != 0 or [*strj][-1] != '3':
		list2.append(j)
for val in list1:
	print(list2[val - 1])


s = int(input())
lst = []
for i in range(1, 1670):
	i = str(i)
	if int(i) % 3 != 0:
		if i.endswith('3'):
			pass
		else:
			lst.append(i)
	else:
		pass
lst1 = []
for j in range(s):
	s2 = int(input())
	lst1.append(lst[s2 - 1])
for q in lst1:
	print(q)


for _ in range(int(input())):
	q = int(input())
	l = list(range(1, q + q))
	l2 = list(range(1, q + q))
	for i in l:
		if i % 3 == 0:
			l2.remove(i)
			continue
		elif i % 10 == 3:
			l2.remove(i)
	print(l2[q - 1])


ans = []
for i in range(1, 2000):
	if i % 3 != 0 and i % 10 != 3:
		ans.append(i)
n = int(input())
for i in range(n):
	k = int(input())
	print(ans[k - 1])


a = [i for i in range(1, 10000) if not (i % 3 == 0 or i % 10 == 3)]
T = int(input())
for _ in range(T):
	k = int(input())
	print(a[k - 1])


ans = [0]
for i in range(1, 4000):
	if i % 3 != 0 and i % 10 != 3:
		ans.append(i)
for _ in range(int(input())):
	print(ans[int(input())])


N = 10010
t = int(input())
nums = []

def check(x):
	if x % 3 == 0 or x % 10 == 3:
		return False
	return True

def init():
	for i in range(1, N):
		if check(i):
			nums.append(i)
init()
for _ in range(t):
	k = int(input())
	print(nums[k - 1])


l = [i for i in range(10000) if i % 3 != 0 and i % 10 != 3]
t = int(input())
for _ in range(t):
	k = int(input())
	print(l[k - 1])


from itertools import count, islice
positions = list(map(int, open(0).read().split()[1:]))
sequence = list(islice(filter(lambda x: (x - 3) % 10, filter(3 .__rmod__, count(-1))), None, max(positions) + 1))
print(*map(sequence.__getitem__, positions), sep='\n')


n = int(input())
a = []
for _ in range(n):
	a.append(int(input()))
a1 = max(a)
b1 = 1
b2 = 1
c = {}
while b1 <= a1:
	if b2 % 3 != 0 and b2 % 10 != 3:
		c[b1] = b2
		b1 += 1
		b2 += 1
	else:
		b2 += 1
for i in a:
	print(c[i])


test = int(input())
limit = 0
inputs = []
for i in range(test):
	val = int(input())
	limit = max(limit, val)
	inputs.append(val)
res = []
i = 1
while len(res) < limit:
	if i % 3 != 0 and i % 10 != 3:
		res.append(i)
	i += 1
for num in inputs:
	print(res[num - 1])


count = int(input())
k_list = []
series_list = []
for i in range(count):
	k_list.append(int(input()))
a = 1
while len(series_list) != 1000:
	a_end = int(str(a)[len(str(a)) - 1])
	if (a % 3 != 0 and a_end != 3) and a % 3 != 0 and (a_end != 3):
		series_list.append(a)
	a += 1
for i in k_list:
	print(series_list[i - 1])


for _ in range(int(input())):
	k = int(input())
	index = 1
	num = 1
	while index <= k:
		if num % 3 != 0 and num % 10 != 3:
			index += 1
		num += 1
	print(num - 1)


t = int(input())
while t > 0:
	demo = []
	n = int(input())
	i = 1
	count = 1
	while count <= n:
		if i % 3 != 0 and i % 10 != 3:
			demo.append(i)
			count = count + 1
		i = i + 1
	print(demo[-1])
	t = t - 1


a = []
for i in range(1, 2000):
	if i % 3 == 0 or str(i)[-1] == '3':
		continue
	a.append(i)
t = int(input())
for i in range(t):
	n = int(input())
	print(a[n - 1])


z = []
for i in range(1, 100001):
	if i % 3 != 0:
		i = str(i)
		if i[len(i) - 1] != '3':
			z.append(i)
t = int(input())
for i in range(t):
	n = int(input())
	print(z[n - 1])


a = []
for k in range(1, 2000):
	if k % 3 != 0:
		if k % 10 != 3:
			a.append(k)
t = int(input())
for z in range(t):
	n = int(input())
	for l in range(len(a)):
		if n == l:
			print(a[l - 1])


t = int(input())
lst = [1, 2, 4, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 40, 41, 44, 46, 47, 49, 50, 52, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 70, 71, 74, 76, 77, 79, 80, 82, 85, 86, 88, 89, 91, 92, 94, 95, 97, 98, 100, 101, 104, 106, 107, 109, 110, 112, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 130, 131, 134, 136, 137, 139, 140, 142, 145, 146, 148, 149, 151, 152, 154, 155, 157, 158, 160, 161, 164, 166, 167, 169, 170, 172, 175, 176, 178, 179, 181, 182, 184, 185, 187, 188, 190, 191, 194, 196, 197, 199, 200, 202, 205, 206, 208, 209, 211, 212, 214, 215, 217, 218, 220, 221, 224, 226, 227, 229, 230, 232, 235, 236, 238, 239, 241, 242, 244, 245, 247, 248, 250, 251, 254, 256, 257, 259, 260, 262, 265, 266, 268, 269, 271, 272, 274, 275, 277, 278, 280, 281, 284, 286, 287, 289, 290, 292, 295, 296, 298, 299, 301, 302, 304, 305, 307, 308, 310, 311, 314, 316, 317, 319, 320, 322, 325, 326, 328, 329, 331, 332, 334, 335, 337, 338, 340, 341, 344, 346, 347, 349, 350, 352, 355, 356, 358, 359, 361, 362, 364, 365, 367, 368, 370, 371, 374, 376, 377, 379, 380, 382, 385, 386, 388, 389, 391, 392, 394, 395, 397, 398, 400, 401, 404, 406, 407, 409, 410, 412, 415, 416, 418, 419, 421, 422, 424, 425, 427, 428, 430, 431, 434, 436, 437, 439, 440, 442, 445, 446, 448, 449, 451, 452, 454, 455, 457, 458, 460, 461, 464, 466, 467, 469, 470, 472, 475, 476, 478, 479, 481, 482, 484, 485, 487, 488, 490, 491, 494, 496, 497, 499, 500, 502, 505, 506, 508, 509, 511, 512, 514, 515, 517, 518, 520, 521, 524, 526, 527, 529, 530, 532, 535, 536, 538, 539, 541, 542, 544, 545, 547, 548, 550, 551, 554, 556, 557, 559, 560, 562, 565, 566, 568, 569, 571, 572, 574, 575, 577, 578, 580, 581, 584, 586, 587, 589, 590, 592, 595, 596, 598, 599, 601, 602, 604, 605, 607, 608, 610, 611, 614, 616, 617, 619, 620, 622, 625, 626, 628, 629, 631, 632, 634, 635, 637, 638, 640, 641, 644, 646, 647, 649, 650, 652, 655, 656, 658, 659, 661, 662, 664, 665, 667, 668, 670, 671, 674, 676, 677, 679, 680, 682, 685, 686, 688, 689, 691, 692, 694, 695, 697, 698, 700, 701, 704, 706, 707, 709, 710, 712, 715, 716, 718, 719, 721, 722, 724, 725, 727, 728, 730, 731, 734, 736, 737, 739, 740, 742, 745, 746, 748, 749, 751, 752, 754, 755, 757, 758, 760, 761, 764, 766, 767, 769, 770, 772, 775, 776, 778, 779, 781, 782, 784, 785, 787, 788, 790, 791, 794, 796, 797, 799, 800, 802, 805, 806, 808, 809, 811, 812, 814, 815, 817, 818, 820, 821, 824, 826, 827, 829, 830, 832, 835, 836, 838, 839, 841, 842, 844, 845, 847, 848, 850, 851, 854, 856, 857, 859, 860, 862, 865, 866, 868, 869, 871, 872, 874, 875, 877, 878, 880, 881, 884, 886, 887, 889, 890, 892, 895, 896, 898, 899, 901, 902, 904, 905, 907, 908, 910, 911, 914, 916, 917, 919, 920, 922, 925, 926, 928, 929, 931, 932, 934, 935, 937, 938, 940, 941, 944, 946, 947, 949, 950, 952, 955, 956, 958, 959, 961, 962, 964, 965, 967, 968, 970, 971, 974, 976, 977, 979, 980, 982, 985, 986, 988, 989, 991, 992, 994, 995, 997, 998, 1000, 1001, 1004, 1006, 1007, 1009, 1010, 1012, 1015, 1016, 1018, 1019, 1021, 1022, 1024, 1025, 1027, 1028, 1030, 1031, 1034, 1036, 1037, 1039, 1040, 1042, 1045, 1046, 1048, 1049, 1051, 1052, 1054, 1055, 1057, 1058, 1060, 1061, 1064, 1066, 1067, 1069, 1070, 1072, 1075, 1076, 1078, 1079, 1081, 1082, 1084, 1085, 1087, 1088, 1090, 1091, 1094, 1096, 1097, 1099, 1100, 1102, 1105, 1106, 1108, 1109, 1111, 1112, 1114, 1115, 1117, 1118, 1120, 1121, 1124, 1126, 1127, 1129, 1130, 1132, 1135, 1136, 1138, 1139, 1141, 1142, 1144, 1145, 1147, 1148, 1150, 1151, 1154, 1156, 1157, 1159, 1160, 1162, 1165, 1166, 1168, 1169, 1171, 1172, 1174, 1175, 1177, 1178, 1180, 1181, 1184, 1186, 1187, 1189, 1190, 1192, 1195, 1196, 1198, 1199, 1201, 1202, 1204, 1205, 1207, 1208, 1210, 1211, 1214, 1216, 1217, 1219, 1220, 1222, 1225, 1226, 1228, 1229, 1231, 1232, 1234, 1235, 1237, 1238, 1240, 1241, 1244, 1246, 1247, 1249, 1250, 1252, 1255, 1256, 1258, 1259, 1261, 1262, 1264, 1265, 1267, 1268, 1270, 1271, 1274, 1276, 1277, 1279, 1280, 1282, 1285, 1286, 1288, 1289, 1291, 1292, 1294, 1295, 1297, 1298, 1300, 1301, 1304, 1306, 1307, 1309, 1310, 1312, 1315, 1316, 1318, 1319, 1321, 1322, 1324, 1325, 1327, 1328, 1330, 1331, 1334, 1336, 1337, 1339, 1340, 1342, 1345, 1346, 1348, 1349, 1351, 1352, 1354, 1355, 1357, 1358, 1360, 1361, 1364, 1366, 1367, 1369, 1370, 1372, 1375, 1376, 1378, 1379, 1381, 1382, 1384, 1385, 1387, 1388, 1390, 1391, 1394, 1396, 1397, 1399, 1400, 1402, 1405, 1406, 1408, 1409, 1411, 1412, 1414, 1415, 1417, 1418, 1420, 1421, 1424, 1426, 1427, 1429, 1430, 1432, 1435, 1436, 1438, 1439, 1441, 1442, 1444, 1445, 1447, 1448, 1450, 1451, 1454, 1456, 1457, 1459, 1460, 1462, 1465, 1466, 1468, 1469, 1471, 1472, 1474, 1475, 1477, 1478, 1480, 1481, 1484, 1486, 1487, 1489, 1490, 1492, 1495, 1496, 1498, 1499, 1501, 1502, 1504, 1505, 1507, 1508, 1510, 1511, 1514, 1516, 1517, 1519, 1520, 1522, 1525, 1526, 1528, 1529, 1531, 1532, 1534, 1535, 1537, 1538, 1540, 1541, 1544, 1546, 1547, 1549, 1550, 1552, 1555, 1556, 1558, 1559, 1561, 1562, 1564, 1565, 1567, 1568, 1570, 1571, 1574, 1576, 1577, 1579, 1580, 1582, 1585, 1586, 1588, 1589, 1591, 1592, 1594, 1595, 1597, 1598, 1600, 1601, 1604, 1606, 1607, 1609, 1610, 1612, 1615, 1616, 1618, 1619, 1621, 1622, 1624, 1625, 1627, 1628, 1630, 1631, 1634, 1636, 1637, 1639, 1640, 1642, 1645, 1646, 1648, 1649, 1651, 1652, 1654, 1655, 1657, 1658, 1660, 1661, 1664, 1666]
for _ in range(t):
	k = int(input())
	print(lst[k - 1])


n = int(input())
l = []
for i in range(1, 1667):
	if i % 3 != 0 and i % 10 != 3:
		l.append(i)
for i in range(n):
	x = int(input())
	print(l[x - 1])


for i in range(int(input())):
	k = int(input())
	c = 0
	j = 1
	while True:
		if j % 3 != 0 and j % 10 != 3:
			k -= 1
		if k == 0:
			print(j)
			break
		j += 1


n = int(input())
col = 0
lis = []
while n != col:
	k = int(input())
	gen = [i for i in range(1, 2 * k) if i % 3 != 0 and i % 10 != 3]
	lis.append(gen[k - 1])
	col += 1
for i in lis:
	print(i)


dp = []
n = 1
while len(dp) != 1000:
	while n % 10 == 3 or n % 3 == 0:
		n += 1
	dp.append(n)
	n += 1
t = int(input())
for i in range(t):
	print(dp[int(input()) - 1])