NOTE :This problem is just a test problem. The submissions to this problem will not be counted in the final ranklist for prize distribution. We apologize for the inconvenience caused.  


Problem description
Given two integers A and B that are not necessarily in base-10, find the smallest possible A + B in base-10.

For example,
A = 213, possibly base-4 (39 in base-10)
B = 4721, possibly base-8 (2513 in base-10)
A + B = 39 + 2513 = 2552 

Input

First line of the input contains a positive integer T (1 <= T <= 100), the number of cases. Each case contains
two positive integers A and B. A and B will contain at most 5 digits, each digit will be between 0 and 9,
inclusive, and no leading zeroes.

Output

For each case, output an integer in base-10 denoting the smallest possible A + B.

Example
Input:
3
213 4721
1001 90
638 241

Output:
2552
99
592
import sys

def base(n):
	max=0
	while(n!=0):
		if(n%10 > max):
			max=n%10
			
		n=n/10
	return max+1

def convert(n,b):
	i=0
	sum=0
	while(n!=0):
		sum+=(n%10)*pow(b,i)
		i=i+1
		n=n/10
	
	return sum

def main():
	t=int(raw_input())
	
	while(t!=0):
		a,b=map(int,raw_input().split())
		a=convert(a,base(a))
		b=convert(b,base(b))
		print a+b
		t=t-1
if __name__ == '__main__':
	main()