The chef was not happy with the binary number system, so he designed a new machine which is having 6 different states, i.e. in binary there is a total of 2 states as 0 and 1. Now, the chef is confused about how to correlate this machine to get an interaction with Integer numbers, when N(Integer number) is provided to the system, what will be the Nth number that system will return(in Integer form), help the chef to design this system.

-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow. 
- Each test case contains a single line of input, $N$. 

-----Output:-----
For each test case, output in a single line answer given by the system.

-----Constraints-----
- $1 \leq T \leq 10^5$
- $1 \leq N \leq 10^5$

-----Sample Input:-----
2
3
5

-----Sample Output:-----
7
37

-----EXPLANATION:-----
Initial numbers for system = [1, 6, 7, 36, 37, 42, 43, 216, …..
For 1) 3rd Number for the system will be 7.
For 2) 5th Number for the system will be 37.

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
from sys import stdin, stdout
l = [1, 6, 7]
c = 1
for x in range(3, 100001):
	if x % 2 == 1:
		a = l[c] * 6
		l.append(a)
	else:
		l.append(a + 1)
		c += 1
n = int(stdin.readline())
for _ in range(n):
	s = int(stdin.readline())
	print(l[s - 1])


n = int(input())
l = [1]
ind = 0
for i in range(n):
	t = int(input())
	if len(l) >= t:
		print(l[t - 1])
	else:
		while len(l) < t:
			l += [l[ind] * 6, l[ind] * 6 + 1]
			ind += 1
		print(l[t - 1])


arr = [1]
for i in range(1, 18):
	x = 6 ** i
	b = [x]
	for j in arr:
		b.append(j + x)
	arr += b
arr.sort()
for t in range(int(input())):
	n = int(input())
	print(arr[n - 1])


def nthMagicNo(n):
	pow = 1
	answer = 0
	while n:
		if n & 1:
			answer += pow
		n >>= 1
		pow = pow * 6
	return answer
for _ in range(int(input())):
	a = int(input())
	print(nthMagicNo(a))


t = int(input())
while t:
	t = t - 1
	n = int(input())
	x = bin(n)
	x = x[2:]
	x = x[::-1]
	z = 1
	s = 0
	for i in range(len(x)):
		if x[i] == '1':
			s += z
		z *= 6
	print(s)


for _ in range(int(input())):
	n = bin(int(input()))
	n = int(n[2:], 6)
	print(n)


import sys
T = int(input())
system = [0, 1]
new_multiplier = 1
while len(system) < 110000:
	new_multiplier *= 6
	new_list = list((int(x + new_multiplier) for x in system))
	system += new_list
for t in range(T):
	N = int(input())
	print(system[N])


for _ in range(int(input())):
	N = int(input())
	p = bin(N)[2:]
	ans = 0
	cnt = 0
	p = p[-1::-1]
	for i in p:
		ans += int(i) * 6 ** cnt
		cnt += 1
	print(ans)