Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 
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$

----- Sample Input 1 ------ 
6
24 60
34 50
10 11
10 12
11 11
1 1
----- Sample Output 1 ------ 
19
20
10
11
10
1
----- explanation 1 ------ 
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.

Source: codechef | Difficulty: MEDIUM
Tags: String algorithms

Data structures

Complete search


Solutions:
for _ in range(int(input())):
	(h, m) = map(int, input().split())
	H = h - 1
	M = m - 1
	print(min(M, H, 9) + 1 + min(H, M // 11) + min(M, H // 11) + min(H // 11, M // 11))


t = int(input())
for _ in range(t):
	(h, m) = [int(i) for i in input().split()]
	iden_time = 0
	for i in range(h):
		if i < 10:
			min = i
			if min < m:
				iden_time += 1
			if i > 0:
				min = i * 10 + i
				if min < m:
					iden_time += 1
		if i > 10 and i % 10 == i // 10:
			min = i
			if min < m:
				iden_time += 1
			min = i % 10
			if min < m:
				iden_time += 1
	print(iden_time)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def outp(n):
	sys.stdout.write(str(n) + '\n')

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
ans = []
for _ in range(inp()):
	(H, M) = inlt()
	an = 0
	for i in range(10):
		if i < H and i < M:
			an += 1
		else:
			break
	for i in range(1, 10):
		if i < H and 11 * i < M:
			an += 1
		else:
			break
	for i in range(1, 10):
		if 11 * i < H and i < M:
			an += 1
		else:
			break
	for i in range(1, 10):
		if 11 * i < H and 11 * i < M:
			an += 1
		else:
			break
	ans.append(an)
outplt(ans)


def is_ident(hr, min):
	quer = str(hr) + str(min)
	for i in quer:
		if i == quer[0]:
			pass
		else:
			return False
	return True

def main():
	t = int(input())
	while t > 0:
		(hr, min) = map(int, input().split())
		count = 0
		for x in range(hr):
			for i in range(min):
				if is_ident(x, i):
					count += 1
		print(count)
		t -= 1
main()


t = int(input())
for i in range(t):
	time = list(map(int, input().split()))
	hours = time[0]
	minutes = time[1]
	count = 0
	for hour in range(hours):
		for minute in range(minutes):
			if set(str(hour)) == set(str(minute)) and len(set(str(hour))) == 1:
				count += 1
	print(count)


T = int(input())
for i in range(T):
	(H, M) = map(int, input().split())
	count = 0
	for h in range(H):
		for m in range(M):
			temp = str(h) + str(m)
			if temp[0] * len(temp) == temp:
				count = count + 1
	print(count)


t = int(input())
while t > 0:
	(h, m) = map(int, input().split())
	a = 0
	for i in range(h):
		if i <= 9 or i % 10 == i // 10:
			for j in range(m):
				if j <= 9 or j % 10 == j // 10:
					if j % 10 == i % 10:
						a += 1
	print(a)
	t -= 1


t = int(input())
while t:
	(h, m) = map(int, input().split())
	i = 1
	count = 0
	while i <= 9 and i <= h - 1:
		if i <= m - 1:
			count = count + 1
		if i * 11 <= m - 1:
			count = count + 1
		if i * 11 <= h - 1 and i <= m - 1:
			count = count + 1
		if i * 11 <= h - 1 and i * 11 <= m - 1:
			count = count + 1
		i = i + 1
	t = t - 1
	count = count + 1
	print(count)


fine = [11, 22, 33, 44, 55, 66, 77, 88, 99]
t = int(input())
for _ in range(t):
	l = input().split()
	h = int(l[0])
	m = int(l[1])
	th = list()
	tm = list()
	for i in range(h):
		if i <= 9:
			th.append(i)
		elif i in fine:
			th.append(i)
	for i in range(m):
		if i <= 9:
			tm.append(i)
		elif i in fine:
			tm.append(i)
	c = 0
	f = True
	for i in th:
		f = True
		for j in tm:
			f = True
			s = str(i) + str(j)
			for k in range(len(s) - 1):
				if not s[k] == s[k + 1]:
					f = False
					break
			if f == True:
				c = c + 1
	print(c)


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	c = 0
	for i in range(a):
		i = str(i)
		if len(i) == 1 or i[0] == i[1]:
			for j in range(b):
				j = str(j)
				if len(j) == 1 or j[0] == j[1]:
					if j[0] == i[0]:
						c += 1
	print(c)
	t -= 1


t = int(input())
for inh in range(0, t):
	(h, m) = map(int, input().split())
	ans = 1
	(uni, bi) = (1, 11)
	while uni <= 9:
		(a, b) = (0, 0)
		if uni < h:
			a += 1
		if bi < h:
			a += 1
		if uni < m:
			b += 1
		if bi < m:
			b += 1
		if a == 0 and b == 0:
			break
		else:
			z = a * b
			ans += z
			uni += 1
			bi += 11
	print(ans)


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	count = 0
	for i in range(h):
		for j in range(m):
			s = str(i) + str(j)
			if s.count(s[0]) == len(s):
				count += 1
	print(count)


n = int(input())
for i in range(n):
	(h, m) = map(int, input().split())
	a = 0
	for ho in range(h):
		for mi in range(m):
			ans = str(ho) + str(mi)
			if ans.count(ans[0]) == len(ans):
				a += 1
	print(a)


for _ in range(int(input())):
	count = 0
	HM = list(map(int, input().split()))
	for i in range(HM[0]):
		if i <= 9 or i % 11 == 0:
			for j in range(HM[1]):
				if j <= 9 and i % 11 == j != 0:
					count += 1
				elif j / 11 == i != 0 or i / 11 == j != 0:
					count += 1
				elif j == i:
					count += 1
	print(count)


for _ in range(int(input())):
	(H, M) = map(int, input().split())
	c = 0
	for i in range(0, H):
		for j in range(0, M):
			if len(set(str(i))) == 1 and len(set(str(j))) == 1:
				l = list(str(i) + str(j))
				if l == l[::-1]:
					c += 1
	print(c)


tests = int(input())
for i in range(tests):
	(h, m) = map(int, input().split())
	ans = 1
	for j in range(1, h):
		if j < 10 or j % 11 == 0:
			num = j % 10
			if num < m:
				ans += 1
			count = 1
			while num * (10 ** count + 1) < m:
				ans += 1
				count += 1
	print(ans)


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	c = 0
	for i in range(h):
		p = ''
		for j in range(m):
			p = str(i) + str(j)
			if len(p) == p.count(p[0]):
				c += 1
	print(c)


matches = 0

def match_counter(hour, mins, matches):
	for m in range(mins):
		if m == hour and str(m)[0] == str(hour)[-1] or m * 11 == hour:
			matches += 1
		elif m == hour * 11:
			matches += 1
			break
	return matches

def hours_counters(hours, mins, matches):
	for h in range(hours):
		matches = match_counter(h, mins, matches)
	return matches
for test in range(int(input())):
	(hours, mins) = input().split(' ')
	print(hours_counters(int(hours), int(mins), matches))


T = int(input())
for i in range(T):
	tm = list(map(int, input().split()))
	hrs = tm[0]
	mins = tm[1]
	res = 0
	for i in range(hrs):
		for j in range(mins):
			string = str(i) + str(j)
			if string.count(string[0]) == len(string):
				res += 1
	print(res)


def reloj(hora=0, minuto=0):
	arr_str = []
	if hora > 100:
		hora = 100
	if minuto > 100:
		minuto = 100
	for i in range(hora):
		for j in range(minuto):
			arr_str.append(f'{i}:{j}')
	c = 0
	arr_2 = []
	for i in arr_str:
		if len(set(i)) == 2:
			c += 1
	return c
tam = int(input())
arr = []
for i in range(tam):
	arr_1 = input().split()
	mapeo = map(int, arr_1)
	arr.append(list(mapeo))
for i in arr:
	print(reloj(i[0], i[1]))


t = int(input())
while t:
	(h, m) = map(int, input().strip().split())
	i = 0
	j = 0
	f = 0
	c = 0
	for i in range(h):
		if i < 10 or i % 11 == 0:
			for j in range(m):
				if (j < 10 or j % 11 == 0) and str(i)[0] == str(j)[0]:
					f = 1
				c += f
				f = 0
	print(c)
	t -= 1


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	ans = min(10, min(h, m))
	if m % 11 == 0:
		ans += min(m // 11 - 1, h - 1)
	else:
		ans += min(m // 11, h - 1)
	if h % 11 == 0:
		for i in range(1, h // 11):
			if 11 * i < m:
				ans += 2
			elif i < m:
				ans += 1
			else:
				break
	else:
		for i in range(1, h // 11 + 1):
			if 11 * i < m:
				ans += 2
			elif i < m:
				ans += 1
			else:
				break
	print(ans)


for x in range(int(input())):
	(h, m) = map(int, input().split())
	a = 0
	for xx in range(h):
		for xxx in range(m):
			r = str(xx) + str(xxx)
			if r.count(r[0]) == len(r):
				a += 1
	print(a)


t = int(input())
if 1 <= t <= 50:
	for _ in range(t):
		(h, m) = map(int, input().split())
		if 1 <= h <= 100 and 1 <= m <= 100:
			i = 1
			c = 1
			while i <= 9:
				if 0 <= i <= h - 1 and 0 <= 11 * i <= m - 1:
					c = c + 1
				if 0 <= 11 * i <= h - 1 and 0 <= i <= m - 1:
					c = c + 1
				if 0 <= i <= h - 1 and 0 <= i <= m - 1:
					c = c + 1
				if 0 <= 11 * i <= h - 1 and 0 <= 11 * i <= m - 1:
					c = c + 1
				i = i + 1
			print(c)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	s = min(n, m)
	ans = 0
	if s > 9:
		ans += 10
	else:
		ans += s
	for j in range(1, n):
		if j * 11 < m:
			ans += 1
	for k in range(1, m):
		if k * 11 < n:
			ans += 1
	a = int((n - 1) / 11)
	b = int((m - 1) / 11)
	g = min(a, b)
	ans += g
	print(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	for x in range(a):
		for y in range(b):
			k1 = set(list(str(x)))
			k2 = set(list(str(y)))
			if len(k1) == 1 and len(k2) == 1 and (k1 == k2):
				count += 1
	print(count)


try:
	from debug import debug, timer
except ImportError:
	pass
from sys import stdin
input = stdin.readline

def rii():
	return range(int(input().strip()))

def ii():
	return int(input().strip())

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())

def getvals():
	while True:
		yield from input().split()

def tri(n):
	return n * (n + 1) // 2

def smallest_first(m, n):
	return (min(m, n), max(m, n))

class Clock:

	def __init__(self, h, m):
		self.h = h - 1
		self.m = m - 1

	def two_digits(self):
		return sum([all([x <= self.h, x <= self.m]) for x in range(10)])

	def three_digits(self):
		t1 = sum([all([x <= self.h, x * 11 <= self.m]) for x in range(1, 10)])
		t2 = sum([all([x * 11 <= self.h, x <= self.m]) for x in range(1, 10)])
		return t1 + t2

	def four_digits(self):
		return sum([all([x * 11 <= self.h, x * 11 <= self.m]) for x in range(1, 10)])

	def get_doubles(self):
		return self.two_digits() + self.three_digits() + self.four_digits()

def do_codechef():
	for t in rii():
		(h, m) = mii()
		print(Clock(h, m).get_doubles())
do_codechef()
exit()


t = int(input())
for i in range(t):
	time = list(map(int, input().split()))
	hours = time[0]
	minutes = time[1]
	clock = 0
	for i in range(hours):
		for j in range(minutes):
			x = str(i) + str(j)
			if x.count(x[0]) == len(x):
				clock += 1
	print(clock)


for x in range(int(input())):
	(h, m) = map(int, input().split())
	a = 0
	for i in range(h):
		for j in range(m):
			r = str(i) + str(j)
			if r.count(r[0]) == len(r):
				a += 1
	print(a)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	c = 0
	for i in range(x):
		for j in range(y):
			s = str(i) + str(j)
			if s.count(s[0]) == len(s):
				c = c + 1
	print(c)


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	ele_cnt = 0
	for i in range(0, h):
		for j in range(0, m):
			x = str(i)
			y = str(j)
			time = x + ':' + y
			if time.count(time[0]) == len(time) - 1:
				ele_cnt += 1
	print(ele_cnt)


def getCount(h, m, i):
	h = int(h)
	m = int(m)
	h1 = 0
	lst = [11, 22, 33, 44, 55, 66, 77, 88, 99]
	while h1 < h:
		for m1 in range(0, m):
			if h1 < 10:
				if m1 < 10 and h1 == m1:
					count[i] += 1
				if m1 in lst and m1 % 10 == h1:
					count[i] += 1
			else:
				if m1 in lst and h1 == m1:
					count[i] += 1
				if h1 in lst and h1 % 10 == m1:
					count[i] += 1
		h1 += 1
t = int(input())
count = [0] * t
for i in range(0, t):
	(h, m) = input().split()
	getCount(h, m, i)
for i in count:
	print(i)


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	cnt = 0
	for i in range(h):
		for j in range(m):
			cnt += 1
			s = str(i) + str(j)
			for k in s:
				if k != s[0]:
					cnt -= 1
					break
	print(cnt)


for _ in range(int(input())):
	(H, M) = map(int, input().split())
	count = 0
	for i in range(H):
		for j in range(M):
			if i <= 9 and j <= 9 and (i == j):
				count += 1
			elif i <= 9 and j > 10:
				x = j % 10
				y = j // 10
				if i == x and i == y:
					count += 1
			elif i > 10 and j <= 9:
				x = i % 10
				y = i // 10
				if x == j and y == j:
					count += 1
			elif i > 10 and j > 10:
				a = i % 10
				b = i // 10
				c = j % 10
				d = j // 10
				if a == b == c == d:
					count += 1
	print(count)


T = int(input())
while T:
	(hour, mins) = [int(x) for x in input().split()]
	count = 0
	for i in range(hour):
		for j in range(mins):
			if len(set(str(i) + str(j))) == 1:
				count += 1
	print(count)
	T -= 1


T = int(input())
for k in range(T):
	(s, t) = map(int, input().split())
	c = 0
	for i in range(0, s):
		for j in range(0, t):
			b = str(i) + str(j)
			if b.count(b[0]) == len(b):
				c += 1
	print(c)


for x in range(int(input())):
	(h, m) = map(int, input().split())
	a = 0
	for xx in range(h):
		for xxx in range(m):
			r = set(list(str(xxx)))
			if set(list(str(xx))) == r and len(r) == 1:
				a += 1
	print(a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	for i in range(a):
		for j in range(b):
			c = str(i) + str(j)
			d = set(c)
			if len(d) == 1:
				count = count + 1
	print(count)


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	ans = 0
	for i in range(h):
		for j in range(m):
			time = str(i) + str(j)
			store = set(time)
			if len(store) == 1:
				ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	s = input().strip().split()
	h = int(s[0])
	m = int(s[1])
	total = 0
	for i in range(h):
		for j in range(m):
			s = str(i) + str(j)
			s1 = set(s)
			if len(s1) == 1:
				total += 1
	print(total)


for _ in range(int(input())):
	(H, M) = map(int, input().split())
	c = 0
	for i in range(H):
		for j in range(M):
			s = str(i) + str(j)
			if s.count(s[0]) == len(s):
				c = c + 1
	print(c)


for _ in range(int(input())):
	t = list(map(int, input().split()))
	h = t[0]
	m = t[1]
	c = 0
	for i in range(h):
		for j in range(m):
			x = str(i) + str(j)
			if x.count(x[0]) == len(x):
				c += 1
	print(c)


n = int(input())
while n > 0:
	(h, m) = map(int, input().split())
	count = 0
	for i in range(h):
		for j in range(m):
			x = set(list(str(i)))
			y = set(list(str(j)))
			if len(x) == 1 and len(y) == 1 and (x == y):
				count += 1
	print(count)
	n -= 1


t = int(input())
for i in range(t):
	li = input().split()
	h = int(li[0])
	m = int(li[1])
	minutes = []
	ans = 0
	for hours in range(h):
		for minute in range(m):
			s = str(hours) + str(minute)
			if s.count(s[0]) == len(s):
				ans += 1
	print(ans)


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	cnt = 0
	for i in range(h):
		for j in range(m):
			x = set(list(str(i)))
			y = set(list(str(j)))
			if len(x) == 1 and len(y) == 1 and (x == y):
				cnt += 1
	print(cnt)


for _ in range(int(input())):
	(hour, mins) = map(int, input().split())
	count = 0
	for i in range(0, hour):
		for j in range(0, mins):
			time = str(i) + str(j)
			if time.count(time[0]) == len(time):
				count += 1
	print(count)


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	s = min(h, m)
	cnt = 0
	if s > 9:
		cnt += 10
	else:
		cnt += s
	for i in range(1, h):
		if i * 11 < m:
			cnt += 1
	for j in range(1, m):
		if j * 11 < h:
			cnt += 1
	a = int((h - 1) / 11)
	b = int((m - 1) / 11)
	g = min(a, b)
	cnt += g
	print(cnt)


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	count = 0
	for i in range(0, h):
		for j in range(0, m):
			if len(str(i)) < 2 and len(str(j)) < 2:
				if i == j:
					count += 1
			elif len(str(i)) < 2 and len(str(j)) == 2:
				j = str(j)
				if j[0] == j[1] and int(j[0]) == i:
					count += 1
			elif len(str(i)) == 2 and len(str(j)) < 2:
				i = str(i)
				if i[0] == i[1] and int(i[0]) == j:
					count += 1
			elif len(str(i)) == 2 and len(str(j)) == 2:
				j = str(j)
				i = str(i)
				if j[0] == j[1] and i[0] == i[1] and (int(j[0]) == int(i[0])):
					count += 1
	print(count)


from collections import Counter
t = int(input())
for i in range(t):
	(h, m) = [int(x) for x in input().split(' ')]
	ch = Counter([int(str(x)[0]) for x in range(h) if x < 10 or x % 11 == 0])
	cm = Counter([int(str(x)[0]) for x in range(m) if x < 10 or x % 11 == 0])
	ans = 0
	for (k, v) in ch.items():
		ans += v * cm.get(k, 0)
	print(ans)


t = int(input())
for _ in range(t):
	(h, m) = map(int, input().split())
	ans = 0
	for hh in range(h):
		for mm in range(m):
			time = str(hh) + str(mm)
			unique = set(time)
			if len(unique) == 1:
				ans += 1
	print(ans)


case = int(input())
for i in range(case):
	(h, m) = map(int, input().split(' '))
	h = h - 1
	m = m - 1
	hl = len(str(h))
	ml = len(str(m))
	final_sum = 1
	for i in range(1, 10):
		ans = ''
		n = hl
		while n > 0:
			ans = ans + str(i)
			n -= 1
		if int(ans) <= h:
			hrs = len(ans)
		else:
			hrs = len(ans) - 1
		n = ml
		ans = ''
		while n > 0:
			ans = ans + str(i)
			n -= 1
		if int(ans) <= m:
			minu = len(ans)
		else:
			minu = len(ans) - 1
		final_sum += hrs * minu
	print(final_sum)


test = int(input())
for _ in range(test):
	(a, b) = map(int, input().split())
	c = 0
	for j in range(0, a):
		for k in range(0, b):
			if len(list(set(str(j)))) == 1 and len(list(set(str(k)))) == 1:
				l = str(j) + str(k)
				if l == l[::-1]:
					c = c + 1
	print(c)


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	coun = 0
	for i in range(h):
		for j in range(m):
			(a, b) = ([], [])
			a.extend(str(i))
			b.extend(str(j))
			if set(a) == set(b) and len(set(a)) == 1:
				coun += 1
	print(coun)


for _ in range(int(input())):
	(h, m) = map(int, input().split())
	c = 0
	for hi in range(h):
		for mi in range(m):
			if set(str(hi)) == set(str(mi)) and len(set(str(hi))) == 1:
				c += 1
	print(c)


T = int(input())
for t in range(T):
	clock = [int(a) for a in input().split()]
	H = clock[0]
	M = clock[1]
	count = 0
	for h in range(H):
		for m in range(M):
			time_now = str(h) + str(m)
			if time_now == time_now[0] * len(time_now):
				count = count + 1
	print(count)


for _ in range(int(input())):
	(h, m) = map(int, input().split())

	def fun(v):
		v = str(v)
		d = []
		if len(v) == 1:
			d.append(int(v[0]))
		else:
			if int(v[0]) <= int(v[1]):
				d.append(int(v[0]))
			else:
				d.append(int(v[0]) - 1)
			for i in range(1, len(v)):
				d.append(9)
		return d
	H = fun(h - 1)
	M = fun(m - 1)
	total = min(H[0], M[0]) + M[0] * (len(H) - 1) + H[0] * (len(M) - 1) + (len(H) - 1) * (len(M) - 1) * 9
	print(total + 1)


for t in range(int(input())):
	(h, m) = [int(x) for x in input().split(' ')]
	count = 1
	for i in range(1, h):
		if i % 11 == 0 or i < 10:
			temp = i % 10
			while temp < m:
				count += 1
				temp = temp * 10 + i % 10
	print(count)


t = int(input())
h = []
m = []
for i in range(t):
	value = input()
	inputs = value.split(' ')
	h.append(int(inputs[0]))
	m.append(int(inputs[1]))

def dig(h, m):
	count = 0
	hou = ''
	mins = ''
	for i in range(0, h):
		hou = str(i)
		for j in range(0, m):
			mins = str(j)
			temp = hou + mins
			if len(set(temp)) == 1:
				count += 1
	return count
for i in range(t):
	print(dig(h[i], m[i]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	for i in range(n):
		i = str(i)
		if len(i) == 1 or i[0] == i[1]:
			for j in range(m):
				j = str(j)
				if len(j) == 1 or j[0] == j[1]:
					if i[0] == j[0]:
						count = count + 1
	print(count)


def identical(h, m):
	ans = 0
	for hr in range(h):
		for min in range(m):
			if hr < 10 and min < 10:
				if hr == min:
					ans += 1
			elif hr < 10 and min >= 10:
				if hr * 11 == min:
					ans += 1
			elif hr >= 10 and min < 10:
				if hr == min * 11:
					ans += 1
			elif hr % 11 == 0 and min % 11 == 0:
				if hr == min:
					ans += 1
	return ans
T = int(input())
while T != 0:
	(H, M) = map(int, input().split())
	print(identical(H, M))
	T -= 1


x = int(input())
for i in range(x):
	(a, b) = map(int, input().split())
	c = 0
	for j in range(0, a):
		for k in range(0, b):
			if len(list(set(str(j)))) == 1 and len(list(set(str(k)))) == 1:
				l = str(j) + str(k)
				if l == l[::-1]:
					c = c + 1
	print(c)


for _ in range(int(input())):
	(hour, minute) = map(int, input().split())
	count = 0
	for h in range(hour):
		for m in range(minute):
			time = str(h) + str(m)
			if time.count(time[0]) == len(time):
				count = count + 1
	print(count)


times = [(0, 0)]
h = m = 1
while h < 10:
	times.append((h, m))
	times.append((h * 11, m))
	times.append((h, m * 11))
	times.append((h * 11, m * 11))
	h = h + 1
	m = h
t = int(input())
while t:
	(h, m) = [int(i) for i in input().split()]
	num = 0
	for i in times:
		if i[0] < h and i[1] < m:
			num = num + 1
	print(num)
	t = t - 1


t = int(input())
for i in range(t):
	(hours, minutes) = map(int, input().split())
	count = 1
	i = 1
	while i <= 9 and i < hours:
		if i < minutes:
			count += 1
		if i * 10 + i < minutes:
			count += 1
		i += 1
	i = 11
	while i <= 99 and i < hours:
		if i < minutes:
			count += 1
		if i % 10 < minutes:
			count += 1
		i += 11
	print(count)