Given a decimal number N and the base B to which it should be converted. Convert the given number to the given base.
Example 1:
Input:
B = 2
N = 12 
Output:
1100
Explanation:
If the number 12 is converted to a 
number with base 2 we get the binary 
representation of 12 = 1100.
Example 2:
Input:
B = 16
N = 282
Output:
11A
Explanation:
If the number 282 is converted to a 
number with base 16 we get the hexadecimal 
representation of 282 = 11A.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function getNumber() which takes two integer B and N representing the base and the decimal number and returns the number in the given base.
Expected Time Complexity: O(LogN)
Expected Auxiliary Space: O(1)
Constraints:
2 <= B <= 16
1 <= N <= 999999999

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def getNumber(self, B, N):
    	#code here 

Solutions:
class Solution:

	def getNumber(self, B, N):
		sum = ''
		hex_dict = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		while N > 0:
			rem = N % B
			if rem > 9:
				rem_str = hex_dict[rem]
			else:
				rem_str = str(rem)
			sum = sum + rem_str
			N = int(N / B)
		sum = sum[::-1]
		if B > 9:
			return sum
		else:
			return int(sum)


class Solution:

	def getNumber(self, B, N):
		result = ''
		while N > 0:
			rem = N % B
			if rem < 10:
				result += str(rem)
			else:
				result += chr(ord('A') + rem - 10)
			N //= B
		return result[::-1]


class Solution:

	def getNumber(self, B, N):
		s = ''
		while N != 0:
			d = N % B
			if d <= 9:
				s = str(d) + s
			elif d == 10:
				s = 'A' + s
			elif d == 11:
				s = 'B' + s
			elif d == 12:
				s = 'C' + s
			elif d == 13:
				s = 'D' + s
			elif d == 14:
				s = 'E' + s
			elif d == 15:
				s = 'F' + s
			N //= B
		return s


class Solution:

	def getNumber(self, B, N):
		base_num = ''
		while N > 0:
			dig = int(N % B)
			if dig < 10:
				base_num += str(dig)
			else:
				base_num += chr(ord('A') + dig - 10)
			N //= B
		base_num = base_num[::-1]
		return base_num


class Solution:

	def getNumber(self, B, N):
		lut = '0123456789ABCDEF'
		temp = N
		res = ''
		while temp != 0:
			digit = temp % B
			res = lut[digit] + res
			temp //= B
		return res


class Solution:

	def getNumber(self, B, N):
		digits = '0123456789ABCDEF'
		result = ''
		while N != 0:
			rem = N % B
			if rem > 9:
				result = digits[rem] + result
			else:
				result = str(rem) + result
			N = N // B
		return result


import numpy

class Solution:

	def getNumber(self, B, N):
		return numpy.base_repr(N, B)


class Solution:

	def getNumber(self, B, N):
		L = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
		s = ''
		while N > 0:
			s = L[N % B] + s
			N = N // B
		return s


class Solution:

	def getNumber(self, b, n):
		result = ''
		hex_digits = '0123456789ABCDEF'
		while n != 0:
			digit = hex_digits[n % b]
			result = digit + result
			n //= b
		return result


class Solution:

	def getNumber(self, b, n):
		sum = []
		quo = n // b
		rem = n % b
		hex_digits = '0123456789ABCDEF'
		sum.append(hex_digits[rem])
		while quo != 0:
			rem1 = quo % b
			sum.append(hex_digits[rem1])
			quo = quo // b
		return ''.join(map(str, sum[::-1]))


class Solution:

	def getNumber(self, B, N):
		alphas = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		array = []
		num = N
		while N >= 1:
			k = N % B
			if k > 9:
				array.insert(0, alphas[k])
			else:
				array.insert(0, str(k))
			N = N // B
		return ''.join(array)


class Solution:

	def getNumber(self, B, N):
		con = ''
		data = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
		while N > 0:
			r = N % B
			if r > 9:
				con += data[r - 10]
			else:
				con += str(r)
			N = N // B
		return con[::-1]


class Solution:

	def getNumber(self, B, N):
		a = ''
		while N > 0:
			b = N % B
			if b > 9:
				if b == 10:
					b = 'A'
				elif b == 11:
					b = 'B'
				elif b == 12:
					b = 'C'
				elif b == 13:
					b = 'D'
				elif b == 14:
					b = 'E'
				elif b == 15:
					b = 'F'
				a = a + b
			else:
				a = a + str(b)
			N = N // B
		a = a[::-1]
		return a


class Solution:

	def getNumber(self, B, N):
		h = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		res = ''
		while N != 0:
			r = N % B
			if B > 10:
				if r in h:
					res = h[r] + res
				else:
					res = str(r) + res
			else:
				res = str(r) + res
			N = N // B
		return res


class Solution:

	def getNumber(self, B, N):
		dict1 = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		ans = ''
		while N > 0:
			rem = N % B
			if rem >= 10:
				ans += dict1[rem]
			else:
				ans += str(rem)
			N = N // B
		return ans[::-1]


class Solution:

	def getNumber(self, N, B):
		result = []
		c = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F']
		while True:
			x = B % N
			if N > 10 and x > 9:
				result.append(c[x])
			else:
				result.append(x)
			B = B // N
			if B == 0:
				break
		result.reverse()
		result = ''.join([str(ele) for ele in result])
		return result


import numpy as np

class Solution:

	def getNumber(self, B, N):
		return np.base_repr(N, B)


class Solution:

	def getNumber(self, B, N):
		hashmap = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		res = ''
		while N:
			temp = N % B
			N = N // B
			if temp in hashmap:
				temp = hashmap[temp]
			res = str(temp) + res
		return res


class Solution:

	def getNumber(self, B, N):
		res = []
		while N:
			add = N % B
			if add < 10:
				res.append(add)
			else:
				res.append('ABCDEFGH'[add - 10])
			N //= B
		res.reverse()
		res = ''.join(map(str, res))
		return res


class Solution:

	def getNumber(self, B, N):
		s = '0123456789ABCDEFG'
		res = []
		while N:
			res.append(s[N % B])
			N //= B
		return ''.join(res[::-1])


class Solution:

	def getNumber(self, B, N):
		rem = ''
		while N > 0:
			a = str(N % B)
			if N % B == 10:
				a = 'A'
			if N % B == 11:
				a = 'B'
			if N % B == 12:
				a = 'C'
			if N % B == 13:
				a = 'D'
			if N % B == 14:
				a = 'E'
			if N % B == 15:
				a = 'F'
			if N % B == 15:
				a = 'G'
			rem = a + rem
			N = int(N / B)
		return rem


class Solution:

	def getNumber(self, B, N):
		symbols = '0123456789ABCDEFG'
		ans = []
		while N:
			ans.append(symbols[N % B])
			N //= B
		return ''.join(reversed(ans))


class Solution:

	def getNumber(self, B, N):
		s = ''
		while N > 0:
			a = N % B
			if a > 9:
				a = hex(a)
				a = str(a)
				a = a[2]
			N = N // B
			s = s + str(a).upper()
		return s[::-1]


class Solution:

	def getNumber(self, B, N):

		def to_char(num):
			if num >= 0 and num <= 9:
				return num
			return chr(55 + num)
		store = B
		remain = ''
		while N > 0:
			remain += str(to_char(N % B))
			N = N // B
		return remain[::-1]


class Solution:

	def getNumber(self, B, N):
		ans = ''
		while N > 0:
			if N % B < 10:
				ans += str(N % B)
			else:
				ans += chr(55 + N % B)
			N = N // B
		return ans[::-1]


class Solution:

	def getNumber(self, B, N):
		s = ''
		st = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		while N > 0:
			rem = N % B
			s += str(st.get(rem)) if rem in st else str(rem)
			N //= B
		return s[::-1]


class Solution:

	def getNumber(self, B, N):
		char_map = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		result = ''
		while N > 0:
			remainder = N % B
			if remainder > 9:
				result += char_map[remainder]
			else:
				result += str(remainder)
			N //= B
		return result[::-1]


class Solution:

	def getNumber(self, B, N):
		if B == 2:
			return bin(N)[2:]
		elif B == 8:
			return oct(N)[2:]
		elif B == 16:
			return hex(N)[2:].upper()
		else:
			x = ''
			while N > 0:
				dig = int(N % B)
				if dig < 10:
					x += str(dig)
				else:
					x += chr(ord('A') + dig - 10)
				N //= B
			return x[::-1]


class Solution:

	def getNumber(self, B, N):
		l = []
		(a, t) = (0, 0)
		while N:
			t = N % B
			N = N // B
			if t == 10:
				l.append('A')
			elif t == 11:
				l.append('B')
			elif t == 12:
				l.append('C')
			elif t == 13:
				l.append('D')
			elif t == 14:
				l.append('E')
			elif t == 15:
				l.append('F')
			else:
				l.append(str(t))
		l.reverse()
		return ''.join(l)


class Solution:

	def getNumber(self, B, N):
		ANS = ''
		L = ['A', 'B', 'C', 'D', 'E', 'F']
		while N >= B:
			REM = N % B
			if REM >= 10:
				ANS += L[REM - 10]
			else:
				ANS += str(REM)
			N //= B
		if N >= 10:
			ANS += L[N - 10]
		else:
			ANS += str(N)
		return ANS[::-1]


class Solution:

	def getNumber(self, B, N):
		value = ''
		while N > 0:
			modVal = N % B
			if modVal > 9:
				if modVal == 10:
					modVal = 'A'
				elif modVal == 11:
					modVal = 'B'
				elif modVal == 12:
					modVal = 'C'
				elif modVal == 13:
					modVal = 'D'
				elif modVal == 14:
					modVal = 'E'
				elif modVal == 15:
					modVal = 'F'
			value = value + str(modVal)
			N = int(N / B)
		value = value[::-1]
		return value


class Solution:

	def getNumber(self, B: int, N: int) -> str:
		from collections import deque
		digits = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		result = deque()
		while N:
			digit = digits[N % B]
			result.appendleft(digit)
			N //= B
		return ''.join(result)


class Solution:

	def getNumber(self, B, N):
		dig = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		res = []
		while N:
			res.append(dig[N % B])
			N = N // B
		return ''.join(reversed(res))


import numpy as np

class Solution:

	def getNumber(self, B, N):
		digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		res = []
		while N:
			res.append(digits[N % B])
			N //= B
		return ''.join(reversed(res))


def numtochar(x):
	if x <= 9:
		return str(x)
	return chr(ord('A') + (x - 10))

class Solution:

	def getNumber(self, B, N):
		l = []
		x = N
		while x > 0:
			y = x % B
			l.append(numtochar(y))
			x //= B
		return ''.join(reversed(l))


class Solution:

	def getNumber(self, B, N):
		v = ''
		r = 0
		while N > 0:
			r = N % B
			N = N // B
			if r == 10:
				v = v + 'A'
			elif r == 11:
				v = v + 'B'
			elif r == 12:
				v = v + 'C'
			elif r == 13:
				v = v + 'D'
			elif r == 14:
				v = v + 'E'
			elif r == 15:
				v = v + 'F'
			else:
				v = v + str(r)
		return v[::-1]


class Solution:

	def getNumber(self, B, N):
		d = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		ans = ''
		while N:
			ans += d[N % B]
			N //= B
			if N < B:
				ans += d[N]
				break
		return ans[::-1]


class Solution:

	def getNumber(self, B, N):
		(dig, base_num) = (0, '')
		if B == 2:
			return str(bin(N)).replace('0b', '')
		elif B == 8:
			return str(oct(N)).replace('0o', '')
		elif B == 16:
			return str(hex(N).upper()).replace('0X', '')
		elif B == 10:
			return N
		else:
			num = N
			while num > 0:
				dig = int(num % B)
				if dig < 10:
					base_num += str(dig)
				else:
					base_num += chr(ord('A') + dig - 10)
				num = num // B
			base_num = base_num[::-1]
			return base_num


import math

class Solution:

	def getNumber(self, B, N):
		base = B
		num = N
		base_num = ''
		while num > 0:
			dig = int(num % base)
			if dig < 10:
				base_num += str(dig)
			else:
				base_num += chr(ord('A') + dig - 10)
			num //= base
		base_num = base_num[::-1]
		return base_num


class Solution:

	def getNumber(self, B, N):
		res = ''
		alp = 'ABCDEF'
		while N > 0:
			temp = N % B
			N = N // B
			if temp > 9:
				res += alp[temp % 10]
			else:
				res += str(temp)
		return res[::-1]


class Solution:

	def getNumber(self, B, N):
		res = ''
		while N > 0:
			if N % B == 10:
				res += 'A'
			elif N % B == 11:
				res += 'B'
			elif N % B == 12:
				res += 'C'
			elif N % B == 13:
				res += 'D'
			elif N % B == 14:
				res += 'E'
			elif N % B == 15:
				res += 'F'
			else:
				res += str(N % B)
			N = N // B
		res = res[::-1]
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		B = int(input())
		N = int(input())
		ob = Solution()
		ans = ob.getNumber(B, N)
		print(ans)


class Solution:

	def getNumber(self, B, N):
		ans = ''
		val = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
		while N > 0:
			ans += val[int(N % B)]
			N //= B
		return ans[::-1]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		B = int(input())
		N = int(input())
		ob = Solution()
		ans = ob.getNumber(B, N)
		print(ans)


class Solution:

	def getNumber(self, B, N):
		l = []
		while N != 0:
			l.append(N % B)
			N = N // B
		d = len(l)
		m = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}
		t = ''
		for i in range(d - 1, -1, -1):
			if l[i] < 10:
				t += str(l[i])
			else:
				t += m[l[i]]
		return t


class Solution:

	def getNumber(self, B, N):
		base = ''
		while N > 0:
			d = int(N % B)
			if d >= 0 and d <= 9:
				base += str(d)
			else:
				base = base + chr(ord('A') + d - 10)
			N //= B
		return base[::-1]


class Solution:

	def getNumber(self, B, N):
		if B == 10:
			return str(N)
		elif B == 2:
			return '{0:b}'.format(N)
		elif B == 8:
			return '{0:o}'.format(N)
		elif B == 16:
			return '{0:X}'.format(N)
		else:
			res = ''
			while N != 0:
				d = N % B
				if d == 10:
					res = 'A' + res
				elif d == 11:
					res = 'B' + res
				elif d == 12:
					res = 'C' + res
				elif d == 13:
					res = 'D' + res
				elif d == 14:
					res = 'E' + res
				else:
					res = str(d) + res
				N //= B
			return res


class Solution:

	def getRemainder(remainder):
		if remainder == 10:
			return 'A'
		elif remainder == 11:
			return 'B'
		elif remainder == 12:
			return 'C'
		elif remainder == 13:
			return 'D'
		elif remainder == 14:
			return 'E'
		elif remainder == 15:
			return 'F'
		elif remainder == 16:
			return 'G'
		else:
			return str(remainder)

	def getNumber(self, B, N):
		remainders = []
		while N:
			remainders.append(Solution.getRemainder(N % B))
			N //= B
		return ''.join(remainders[::-1])


class Solution:

	def getNumber(self, B, N):
		ans = ''
		while N > 0:
			r = N % B
			if r >= 10:
				r = chr(r + 55)
			ans = str(r) + ans
			N //= B
		return ans


class Solution:

	def getNumber(self, N, B):
		l = []
		while B > 0:
			a = B % N
			if a > 9:
				i = a % 10
				a = chr(65 + i)
			l.insert(0, a)
			B = B // N
		s = ''
		for x in l:
			s = s + str(x)
		return s


class Solution:

	def getNumber(self, B, N):
		ans = ''
		while N:
			dig = N % B
			if dig < 10:
				ans += str(dig)
			else:
				ans += chr(ord('A') - 10 + dig)
			N //= B
		return str(ans[::-1])


class Solution:

	def getNumber(self, B, N):
		string = ''
		num = N
		syllable = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
		while num > 0:
			d = num % B
			string = syllable[d] + string
			num = int(num / B)
		return string


class Solution:

	def getNumber(self, B, N):
		conversion_table = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
		(d, r) = (1, 0)
		s = []
		h = ''
		while d != 0:
			if B > 9:
				r = N % B
				h = conversion_table[r] + h
				d = N // B
				N = d
			else:
				d = N // B
				r = N % B
				N = d
				s.append(r)
		s.reverse()
		if B > 9:
			return h
		return ''.join(map(str, s))


class Solution:

	def getNumber(self, B, N):
		x = 10
		string = ''
		while N >= B:
			r = N % B
			N = N // B
			if r > 9:
				s = r - x
				string += chr(65 + s)
			else:
				string += str(r)
		if N > 9:
			s = N - x
			string += chr(65 + s)
		else:
			string += str(N)
		return string[::-1]


import math

class Solution:
	DIGIT_TABLE = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'}

	def getNumber(self, B, N):
		X = N
		num_digits = math.floor(math.log(N, B))
		bases = [1]
		new_digits = []
		for i in range(0, num_digits):
			bases.append(bases[-1] * B)
		for i in range(num_digits, -1, -1):
			base = bases[i]
			nd = math.floor(X / base)
			new_digits.append(self.DIGIT_TABLE[nd])
			X = X % base
		return ''.join(new_digits)


class Solution:

	def getNumber(self, Num, Value):
		f = ''
		if Value == 0 or Num == 0 or Num > 16:
			return 'Input must follow the following Conditions: 1)Value>0 2)0<Num<17'
		while Value:
			if Value % Num <= 9:
				f = str(Value % Num) + f
			else:
				f = chr(65 + Value % Num % 10) + f
			Value = Value // Num
		return f


class Solution:

	def getNumber(self, B, N):
		ANS = ''
		while N != 0:
			R = N % B
			if R >= 10:
				D = chr(55 + R)
			else:
				D = R
			ANS = str(D) + ANS
			N //= B
		return ANS


from math import log

class Solution:

	def getNumber(self, B, N):
		ANS = ''
		while N != 0:
			R = N % B
			if R >= 10:
				D = chr(55 + R)
			else:
				D = R
			ANS = str(D) + ANS
			N //= B
		return ANS


import string

class Solution:

	def getNumber(self, B, N):
		if N == 0:
			return ''
		i = N % B
		s = ob.getNumber(B, int(N / B))
		if i > 9:
			ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
			i = ascii_uppercase[i - 10]
		return s + str(i)


class Solution:

	def reval(self, n):
		if n >= 0 and n <= 9:
			return chr(n + ord('0'))
		else:
			return chr(n - 10 + ord('A'))

	def getNumber(self, B, N):
		ans = ''
		while N:
			d = N % B
			ans += self.reval(d)
			N = N // B
		return ans[::-1]