abhinav-and-manav
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

Abhinav and Manav both being one of the best coders of SVNIT went onto participate in ACM ICPC Regional Contest. Apparently Manav’s team the 3Horsemen stood ahead of Abhinav’s team akatsuki11 in the contest though both solved the same number of questions .Manav is Abhinav’s greatest rival and Abhinav being adamant about him being The Best gives Manav a challenge described below:

For each positive number N consider the number mirror(N) which is obtained from N by replacing every digit d in the decimal notation(base 10) of N with the digit (9-d). We can now say that mirror(N) is the mirror image of N. For example, reflection of 325 equals 674. Note that leading zeros (if any) should be omitted. So the mirror image of 9 equals 0, so mirror(91) equals 8.
Let us define weight as the product of the number and its mirror image i.e. N * mirror(N). Thus, the weight of the number 20 is equal to 20 ·79 = 1580.

Manav is very weak in mathematics and also he doesn’t want to lose this challenge. So now it’s your job to save Manav from Abhinav’s arrogance. Your task is to find the maximum weight of the numbers in the given range [L,R] (including boundaries).

Input:

First line of input contains number of test cases T. Next T lines contain two positive numbers L and R.

Output:

Find the maximum weight of the numbers in the given range [L, R] for each test case.

Constraints:

1 ≤ T ≤ 24

1 ≤ L ≤ R ≤ 10^9

SAMPLE INPUT
3
3 7
1 1
8 10

SAMPLE OUTPUT
20
8
890

Explanation

For test case 3 

8 * mirror(8) = 8 * 1 = 1

9 * mirror(9) = 9 * 0 = 0

10 * mirror(10) = 10 * 89 = 890

So max(1,0,890) = 890


a = [0,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000]
def a_and_m():
	for t in range(eval(input())):
		l,r = list(map(int,input().split()))
		len_r = len(str(r))
		if l <= a[len_r]/2 and r >= a[len_r]/2:
			#print 'oye'
			v = a[len_r]/2
			tt = str(v)
			ttt = []
			for j in range(len(tt)):
				ttt.append(str(9 - int(tt[j])))
			tt = int(''.join(ttt))
			print(v*tt)
		else:
			if abs(a[len_r]/2 - r) > abs(a[len_r]/2 - l):
				v = l
			else:
				v = r
			tt = str(v)
			ttt = []
			for j in range(len(tt)):
				ttt.append(str(9 - int(tt[j])))
			tt = int(''.join(ttt))
			print(v*tt)
a_and_m()


a = [0,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000]
def max():
	tval=eval(input())
	for t in range(tval):
		l,r = list(map(int,input().split()))
		len_r = len(str(r))
		if l <= a[len_r]/2 and r >= a[len_r]/2:

	     v = a[len_r]/2
		     tt = str(v)
	     mir = []
			     for j in range(len(tt)):
			    	 mir.append(str(9 - int(tt[j])))
			     tt = int(''.join(mir))
			     print(v*tt)
		else:
			if abs(a[len_r]/2 - r) > abs(a[len_r]/2 - l):
				v = l
			else:
	 		v = r
			tt = str(v)
			mir = []
			for j in range(len(tt)):
				mir.append(str(9 - int(tt[j])))
			tt = int(''.join(mir))
			print(v*tt)
max()