A number is a special number if it’s digits only consist 0, 1, 2, 3, 4 or 5. Given a number N and we have to find N-th Special Number. 
Example 1:
Input:
N = 6
Output: 5
Explanation: First 6 numbers are
( 0, 1, 2, 3, 4, 5 )
Ã¢â¬â¹Example 2:
Input: 
N = 7
Output: 10
Explanation: First 7 numbers are
( 0, 1, 2, 3, 4, 5, 10 )
Your Task:
You don't need to read input or print anything. Your task is to complete the function getSpecialNumber() which accepts an integer N and return N^{th} Special Number.
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{5}

Difficulty: MEDIUM
Tags: Mathematics
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3



class Solution:

    def getSpecialNumber(self, n):

        # code here 

Solutions:
class Solution:

	def getSpecialNumber(self, n):
		digits = []
		n -= 1
		while n:
			digits.append(n % 6)
			n //= 6
		ans = 0
		for d in reversed(digits):
			ans = ans * 10 + d
		return ans


class Solution:

	def getSpecialNumber(self, n):
		n = n - 1
		arr = []
		if n < 6:
			return n
		while n > 0:
			rem = n % 6
			arr.append(rem)
			n = n // 6
		ans = ''
		for i in range(len(arr) - 1, -1, -1):
			ans = ans + str(arr[i])
		return ans


class Solution:

	def getSpecialNumber(self, n):
		n -= 1
		num = 0
		c = 1
		while n > 5:
			num += n % 6 * c
			n //= 6
			c *= 10
		num += n * c
		return num


class Solution:

	def getSpecialNumber(self, n):
		n -= 1
		x = 1
		a = 0
		while n:
			a = x * (n % 6) + a
			n //= 6
			x *= 10
		return a


class Solution:

	def getSpecialNumber(self, n):
		r = 1
		ans = 0
		N = n - 1
		if N < 6:
			return N
		while N != 0:
			ans += r * (N % 6)
			N //= 6
			r *= 10
		return ans


class Solution:

	def getSpecialNumber(self, n):
		ans = ''
		k = n
		n = n - 1
		while n > 0:
			ans += str(n % 6)
			n //= 6
		if ans == '':
			ans = '0'
		ans = ans[::-1]
		return int(ans)


def getnum(n):
	n = n - 1
	x = 1
	ans = 0
	while n > 0:
		ans = x * (n % 6) + ans
		n = n // 6
		x = x * 10
	return ans

class Solution:

	def getSpecialNumber(self, n):
		return getnum(n)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.getSpecialNumber(n))


class Solution:

	def getSpecialNumber(self, n):
		if n == 1:
			return 0
		num = ''
		n = n - 1
		while n > 0:
			num += str(n % 6)
			n //= 6
		return num[::-1]


def numberToBase(n, b):
	if n == 0:
		return 0
	s = ''
	while n:
		s += str(int(n % b))
		n //= b
	return int(s[::-1])

class Solution:

	def getSpecialNumber(self, n):
		return numberToBase(n - 1, 6)


class Solution:

	def getSpecialNumber(self, N):
		if N <= 6:
			return N - 1
		tmp = N - 1
		ans = ''
		while tmp != 0:
			ans = str(tmp % 6) + ans
			tmp = tmp // 6
		return int(ans)


class Solution:

	def getSpecialNumber(self, n):
		n -= 1
		ans = 0
		p = 1
		while n:
			ans += p * (n % 6)
			n //= 6
			p *= 10
		return ans


class Solution:

	def getSpecialNumber(self, n):
		res = ''
		N = n
		if N == 1:
			return 0
		N = N - 1
		while N > 0:
			res += str(N % 6)
			N = N // 6
		res = res[::-1]
		return res


class Solution:

	def getSpecialNumber(self, N):
		if N == 1:
			return 0
		N = N - 1
		string = ''
		while N > 0:
			temp = N % 6
			string += str(temp)
			N = N // 6
		string = string[::-1]
		return string


class Solution:

	def getSpecialNumber(self, n):
		if n == 1:
			return 0
		n = n - 1
		Str = ''
		while n > 0:
			digit = n % 6
			Str += str(digit)
			n = n // 6
		return Str[::-1]


class Solution:

	def getSpecialNumber(self, n):
		ans = str()
		n -= 1
		while n:
			ans += str(n % 6)
			n //= 6
		return ans[::-1] if ans else 0


class Solution:

	def getSpecialNumber(self, n):
		ans = []
		n = n - 1
		while n > 0:
			ans.append(n % 6)
			n = n // 6
		ans = ans[::-1]
		s = 0
		for i in ans:
			s = s * 10 + i
		return s


class Solution:

	def getSpecialNumber(self, n):
		res = ''
		x = 0
		n = n - 1
		while n >= 6:
			r = n % 6
			n = n // 6
			res = str(r) + res
		return str(n) + res


class Solution:

	def getSpecialNumber(self, n):
		ans = ''
		d = 0
		n = n - 1
		while True:
			r = n % 6
			m = int(n / 6)
			if m == 0:
				ans = ans + str(r)
				break
			ans = ans + str(r)
			n = m
		return ans[::-1]


class Solution:

	def getSpecialNumber(self, n):
		a = ''
		if n == 1:
			return 0
		z = n - 1
		while z > 0:
			b = z % 6
			a = a + str(b)
			z = z // 6
		a = a[::-1]
		return int(a)


import math

class Solution:

	def getSpecialNumber(self, n):
		if n == 1:
			return 0
		n -= 1
		st = ''
		while n:
			st += str(n % 6)
			n //= 6
		return st[::-1]


class Solution:

	def ans(self, n):
		if n < 6:
			return n
		return n % 6 + 10 * self.ans(n // 6)

	def getSpecialNumber(self, n):
		return self.ans(n - 1)