3:33
It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are identical, but it is not a valid time on a usual digital clock.
The above example was for a usual 24-hour format digital clock. Let's consider a more general clock, where an hour lasts M minutes and a day lasts H hours (therefore, the clock can show any number of hours between 0 and H-1, inclusive, and any number of minutes between 0 and M-1, inclusive). Both the hours and the minutes are shown without leading zeroes in decimal notation and their separator (e.g., ':') doesn't matter.
Can you tell how many minutes during a day will the digital clock have identical digits displayed on it?

Input

The first line of the input contains an integer T - the number of test cases.
Each of the next T lines contains two space-separated integers H and M for one test case.


Output
For each test case, output a single line corresponding to the answer of the problem.

Constraints

1 ≤ T ≤ 50
1 ≤ H, M ≤ 100


Example
Input:
6
24 60
34 50
10 11
10 12
11 11
1 1

Output:
19
20
10
11
10
1

Explanation
Example case 1. A clock shows two identical digits at times 0:0, 1:1, .., 9:9, three identical digits at times 11:1, 22:2, 1:11, 2:22, 3:33, 4:44, 5:55, and four identical digits at times 11:11 and 22:22. So, there are 19 minutes during which the time displayed by the clock will have identical digits. 
Example case 2. Compared to the previous case, the clock doesn't show 5:55, but can show 33:3 and 33:33.
Example case 6. In this example, our day consists of one hour and one hour consists of one minute. Hence, the entire day is just 1 minute - the only time the digital clock will display is 0:0 during the entire day, (i.e. the entire hour, i.e. entire minute). And 0:0 has all digits identical, so the answer is 1.
def identical(i,j):
	#print "i"
	#print i
	#print j
	#print "else"
	i=str(i)+str(j)
	#print "i"
	#print i
	m=0
	n=len(i)
	i=int(i)
	j=i%10
	i=i/10
	#print "j"
	#print j
	#print "i"
	#print i
	while(True):
		#print "while"
		#print "i"
		#print i
		if(i%10!=j and i!=0):
			#print "while-if"
			return 0
		elif(i%10==j and i!=0):
			#print "while-elif-1"
			i=i/10
			m+=1
		elif(i==0):
			#print "while-elif-2"
			break
	if(m==n-1):
		#print "else-if"
		return 1
	else:
		#print "else-else"
		return 0

for k in range(input()):
	#print "1"
	h,m=map(int,raw_input().split())
	#print "result"
	#print h
	#print m
	sum=0
	for i in range(h):
		for j in range(m):
			#print "iden"
			#print identical(i,j)
			sum+=identical(i,j)
			#print "sum"
			#print sum
	#print "result"
	print sum+1