4041 - A+B   

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 BA 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.

Sample Input  Download

Sample Output  Download

Tags




Discuss