Note : This question carries $150$ $points$
There is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor. There are many ships that lead Frodo to Mordor, and he is confused about which one he should board.  Given two-ship numbers $M$ and $N$, Frodo has to solve a problem to find the ship which he should board.
Find the number of pairs (x, y), such that $1<=x<=M$ and $1<=y<=N$, for which $x*y + x+ y = string(x)+string(y)$ is true. 
Also, calculate the number of distinct x satisfying the given condition.  The number of pairs and the number of distinct x will help select Frodo the boat he should board. Help Frodo defeat Sauron. 

-----Input :-----
- First line contains $T$ as number of test cases 
- Each test case contains two integers $M$ and $N$ 

-----Output :-----
- For each test case, print two integers - the number of such pairs (x,y) and the number of distinct x

-----Constraints :-----
- 1 ≤ T ≤ 5000
- 1 ≤  M, N ≤ 10^9

-----Sample Input :-----
1
1 9

-----Sample Output :-----
1 1

-----Explanation :-----
For test case two M=1 and N=9  Pair (1,9) satisfies the above condition 1*9+1+9= “19” and only x=1 satisfies the equation.

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
from math import pow
t = int(input())
for _ in range(t):
	(m, n) = map(int, input().rstrip().split())
	cnt = len(str(n))
	x = pow(10, cnt)
	if n == x - 1:
		print(m * cnt, m)
	else:
		print(m * (cnt - 1), m)


def sol(z):
	r = len(str(z))
	if z < int(str(9) * r):
		r -= 1
	return r
t = int(input())
for _ in range(t):
	(i, j) = map(int, input().split())
	l = i
	print(l * sol(j), l)


for u in range(int(input())):
	(n, m) = list(map(int, input().split()))
	c = 0
	if m < 9:
		print(0, 0)
	else:
		for i in str(m):
			if i == '9':
				c += 1
		if c == len(str(m)):
			print(n * c, n)
		else:
			x = len(str(m)) - 1
			print(x * n, n)


T = int(input())
for i in range(T):
	(m, n) = map(int, input().split())
	cnt = 0
	a = 10
	while n >= a - 1:
		cnt += 1
		a = a * 10
	ans = m * cnt
	if cnt == 0:
		m = 0
	print(ans, m)


for _ in range(int(input())):
	(M, N) = input().split()
	(m, n) = (int(M), int(N))
	x = 1 * 10 ** len(N)
	if n == x - 1:
		print(m * len(N), m)
	else:
		print(m * (len(N) - 1), m)


def solve(y):
	res = len(str(y))
	if y < int(str(9) * res):
		res -= 1
	return res
t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	x = m
	print(x * solve(n), x)


t = int(input())
for _ in range(0, t):
	(m, n) = map(int, input().split())
	if n < 9:
		print(0, 0)
	else:
		s = '9'
		while int(s + '9') < n:
			s += '9'
		print(m * len(s), m)


for i in range(int(input())):
	(m, n) = list(map(int, input().split()))
	if n < 9:
		print(0, 0)
		continue
	k = len(str(n))
	if n == int(str(9) * k):
		ans = k
	else:
		ans = k - 1
	print(m * ans, m)


t = int(input())
for i in range(t):
	(m, n) = input().split()
	if int(n) < 9:
		print(0, 0)
	elif int(n) > 9:
		print(int(m) * (len(n) - 1), int(m))
	else:
		print(int(m), int(m))


for _ in range(int(input())):
	(M, N) = list(map(int, input().split()))
	length = len(str(N))
	initial = '9'
	initial = initial * length
	factor = 0
	if int(initial) > N:
		factor = length - 1
	else:
		factor = length
	if factor == 0:
		M = 0
	print(factor * M, M)


import math
for ad in range(int(input())):
	(m, n) = list(map(int, input().split()))
	a = m
	c = len(str(n))
	if n != int(c * '9'):
		c -= 1
	b = c * a
	print(str(b) + ' ' + str(a))


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	val = '9'
	c = 0
	while int(val) <= n:
		c += 1
		val += '9'
	if m * c != 0:
		print(m * c, m)
	else:
		print(0, 0)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	x = []
	s = str(n)
	a = '9'
	for i in range(len(s)):
		if int(a) <= n:
			x.append(a)
			a += '9'
		else:
			break
	p = m * len(x)
	if p == 0:
		print('0 0')
	else:
		print(p, m)


import math as ma
for _ in range(int(input())):
	(m, n) = list(map(int, input().split()))
	count = 0
	l = int(ma.floor(ma.log(n, 10)))
	if n == pow(10, l + 1) - 1:
		l += 1
	print(m * l, m)


for i in range(int(input())):
	(m, n) = map(int, input().split())
	if n < 9:
		y = 0
	elif n >= 9 and n < 99:
		y = 1
	elif n >= 99 and n < 999:
		y = 2
	elif n >= 999 and n < 9999:
		y = 3
	elif n >= 9999 and n < 99999:
		y = 4
	elif n >= 99999 and n < 999999:
		y = 5
	elif n >= 999999 and n < 9999999:
		y = 6
	elif n >= 9999999 and n < 99999999:
		y = 7
	elif n >= 99999999 and n < 999999999:
		y = 8
	elif n >= 999999999:
		y = 9
	print(m * y, m)


for i in range(int(input())):
	MN = list(map(int, input().split()))
	M = MN[0]
	N = MN[1]
	count = 0
	x = 0
	if N < 9:
		print(count, x)
	elif N < 99:
		count = M
		x = M
		print(count, x)
	elif N < 999:
		count = 2 * M
		x = M
		print(count, M)
	elif N < 9999:
		count = 3 * M
		x = M
		print(count, x)
	elif N < 99999:
		count = 4 * M
		x = M
		print(count, x)
	elif N < 999999:
		count = 5 * M
		x = M
		print(count, x)
	elif N < 9999999:
		count = 6 * M
		x = M
		print(count, x)
	elif N < 99999999:
		count = 7 * M
		x = M
		print(count, x)
	elif N < 999999999:
		count = 8 * M
		x = M
		print(count, x)
	else:
		count = 9 * M
		x = M
		print(count, x)


import math
for i in range(int(input())):
	(m, n) = list(map(int, input().split()))
	val = math.floor(math.log10(n + 1))
	print(m * val, end=' ')
	if val != 0:
		print(m)
	else:
		print(0)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	cn = 0
	i = 10
	while n >= i - 1:
		cn += 1
		i = i * 10
	res = m * cn
	if cn == 0:
		m = 0
	print(res, m)


t = int(input())
ml = []
nl = []
test = set(['9'])
for i in range(t):
	(m, n) = [int(x) for x in input().split(' ')]
	if set(list(str(n))) == test:
		nl.append(len(str(n)))
	else:
		nl.append(len(str(n)) - 1)
	ml.append(m)
for i in range(len(ml)):
	if nl[i] == 0:
		print('0 0')
	else:
		print(ml[i] * nl[i], ml[i])


for _ in range(int(input())):
	(m, n) = list(map(int, input().split()))
	l = len(str(n))
	last = m
	for i in range(1, 12):
		if 10 ** i - 1 > n:
			break
	if i == 1:
		print(0, 0)
	else:
		print(m * (i - 1), m)


for _ in range(0, int(input())):
	(m, n) = map(int, input().split())
	l = [9, 99, 999, 9999, 99999, 999999, 9999999, 99999999]
	t = 0
	if 9 <= n < 99:
		t = 1
	elif 99 <= n < 999:
		t = 2
	elif 999 <= n < 9999:
		t = 3
	elif 9999 <= n < 99999:
		t = 4
	elif 99999 <= n < 999999:
		t = 5
	elif 999999 <= n < 9999999:
		t = 6
	elif 9999999 <= n < 99999999:
		t = 7
	elif 99999999 <= n:
		t = 8
	if t == 0:
		print(0, 0)
	else:
		print(m * t, m)


def lordoftherings(m, n):
	if n < 9:
		return (0, 0)
	digits = len(str(n))
	mul = '9' * digits
	if int(mul) > n:
		mul = digits - 1
	else:
		mul = digits
	return (m * mul % 1000000007, m)
for _ in range(int(input())):
	(m, n) = map(int, input().split())
	(x, y) = lordoftherings(m, n)
	print(x, y)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	if m < 9:
		print(0, 0)
	else:
		m = str(m)
		if len(m) > 1:
			no = len(m) - 1
		else:
			no = 1
		res = n * no
		print(res, n)


try:

	def find(x, y):
		p = x + y + x * y
		s1 = str(x)
		s2 = str(y)
		s3 = str(p)
		return s3 == s1 + s2
	for _ in range(int(input())):
		(m, n) = map(int, input().split())
		n += 1
		l = len(str(n)) - 1
		if l == 0:
			print('0 0')
		else:
			print(l * m, m)
except EOFError as e:
	pass