Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 $\le$ HH $\le$ 23, 00 $\le$ MM $\le$ 59). He looks at the clock every $x$ minutes, and the clock is currently showing time $s$.

How many different palindromes will Victor see in total after looking at the clock every $x$ minutes, the first time being at time $s$?

For example, if the clock starts out as 03:12 and Victor looks at the clock every $360$ minutes (i.e. every $6$ hours), then he will see the times 03:12, 09:12, 15:12, 21:12, 03:12, and the times will continue to repeat. Here the time 21:12 is the only palindrome he will ever see, so the answer is $1$.

A palindrome is a string that reads the same backward as forward. For example, the times 12:21, 05:50, 11:11 are palindromes but 13:13, 22:10, 02:22 are not.


-----Input-----

The first line of the input contains an integer $t$ ($1 \leq t \leq 100$) — the number of test cases. The description of each test case follows.

The only line of each test case contains a string $s$ of length $5$ with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59" (both "HH" and "MM" have exactly two digits) and an integer $x$ ($1 \leq x \leq 1440$) — the number of minutes Victor takes to look again at the clock.


-----Output-----

For each test case, output a single integer — the number of different palindromes Victor will see if he looks at the clock every $x$ minutes starting from time $s$.


-----Examples-----

Input
6
03:12 360
00:00 1
13:22 2
15:15 10
11:11 1440
22:30 27
Output
1
16
10
0
1
1


-----Note-----

The first test case is explained in the statement.

Difficulty: EASY

Solutions:
import math
t = int(input())
palindroms = []
for i in range(24):
	if i % 10 < 6:
		if i < 10:
			e = '0' + str(i)
			a = str(i % 10) + str(i // 10)
			palindroms.append(e + a)
		else:
			a = i % 10 * 10 + i // 10
			palindroms.append(str(i * 100 + a))
for i in range(t):
	(s, y) = input().split()
	(h, m) = s.split(':')
	time = int(h) * 60 + int(m)
	x = int(y)
	otvet = 0
	min_step = math.gcd(x, 1440)
	for j in range(len(palindroms)):
		if (int(palindroms[j]) % 100 + int(palindroms[j]) // 100 * 60 - time) % min_step == 0:
			otvet += 1
	print(otvet)


from math import gcd
palindromes = [int(s.split(':')[0]) * 60 + int(s.split(':')[1]) for s in ['00:00', '01:10', '02:20', '03:30', '04:40', '05:50', '10:01', '11:11', '12:21', '13:31', '14:41', '15:51', '20:02', '21:12', '22:22', '23:32']]
for _ in range(int(input())):
	c = 0
	(s, x) = input().split(' ')
	s = int(s.split(':')[0]) * 60 + int(s.split(':')[1])
	x = int(x)
	for p in palindromes:
		if (p - s) % 1440 % gcd(x, 1440) == 0:
			c += 1
	print(c)


def gcd(x, y):
	if x < y:
		z = x
		x = y
		y = z
	while y != 0:
		z = x % y
		x = y
		y = z
	return x

def f(x):
	a = x % 10
	b = x // 10
	return a * 10 + b
rec = []
for i in range(24):
	for j in range(60):
		if i == f(j):
			rec.append(i * 60 + j)
n = int(input(''))
for i in range(n):
	a = input('').split(' ')
	m = int(a[1])
	t = a[0].split(':')
	x = int(t[0]) * 60 + int(t[1])
	s = 0
	for j in rec:
		if (j - x) % gcd(m, 1440) == 0:
			s += 1
	print(s)


def hcf(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def clock(sx):
	ans = 0
	x = int(sx[1])
	time = int(sx[0][0:2]) * 60 + int(sx[0][3:5])
	k = 1440 // hcf(x, 1440)
	if k == 1440:
		return 16
	for i in range(k):
		t = time % 1440
		if t <= 350:
			if t % 70 == 0:
				ans += 1
		elif t >= 601 and t <= 951:
			if t == 601 or t == 671 or t == 741 or (t == 811) or (t == 881) or (t == 951):
				ans += 1
		elif t >= 1202 and t <= 1412:
			if t == 1202 or t == 1272 or t == 1342 or (t == 1412):
				ans += 1
		time += x
	return ans
tests = int(input())
for _ in range(tests):
	sx = input().split()
	print(clock(sx))


def solve():
	pali = {0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412}
	(c, mins) = input().split()
	mins = int(mins)
	c = c.split(':')
	time = int(c[0]) * 60 + int(c[1])
	res = 0
	if time in pali:
		res += 1
	start = time
	time += mins
	time %= 1440
	while time != start:
		if time in pali:
			res += 1
		time += mins
		time %= 1440
	print(res)
	return

def main():
	for _ in range(int(input())):
		solve()
	return
main()


for _ in range(int(input())):
	(t, x) = input().split()
	(h, m) = map(int, t.split(':'))
	x = int(x)
	t = h * 60 + m
	arr = {0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412}
	ans = 0
	total = 24 * 60
	i = t
	if t in arr:
		ans += 1
	t = (t + x) % total
	while i != t:
		if t in arr:
			ans += 1
		t = (t + x) % total
	print(ans)


t = int(input())
for _ in range(t):
	pal = {0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412}
	(s, x) = [i for i in input().strip().split()]
	s = [int(i) for i in s.split(':')]
	x = int(x)
	org = s[0] * 60 + s[1]
	curr = org
	count = 0
	while True:
		if curr in pal:
			count += 1
		curr += x
		curr %= 1440
		if curr == org:
			break
	print(count)


def solve():
	pp = ['00:00', '01:10', '02:20', '03:30', '04:40', '05:50', '10:01', '11:11', '12:21', '13:31', '14:41', '15:51', '20:02', '21:12', '22:22', '23:32']
	p = []
	for i in pp:
		a = i.split(':')
		p.append(int(a[0]) * 60 + int(a[1]))
	t = int(input())
	for _ in range(t):
		l = input().split()
		hh = l[0].split(':')
		ans = 0
		hi = int(hh[0]) * 60 + int(hh[1])
		if hi in p:
			ans += 1
		m = int(l[1])
		h = (hi + m) % 1440
		while h != hi:
			if h in p:
				ans += 1
			h = (h + m) % 1440
		print(ans)
solve()


def sol():
	vv = input()
	date = vv.split(' ')
	x = int(date[1])
	tm = date[0].split(':')
	h1 = int(tm[0]) // 10
	h2 = int(tm[0]) % 10
	m2 = int(tm[1]) // 10
	m1 = int(tm[1]) % 10
	s = int(tm[0]) * 60 + int(tm[1])
	ans = 0
	if (h1 == m1) & (m2 == h2):
		ans += 1
	tim = s + x
	tim = tim % 1440
	while tim != s:
		h = tim // 60
		m = tim % 60
		h1 = h // 10
		h2 = h % 10
		m2 = m // 10
		m1 = m % 10
		if (h1 == m1) & (h2 == m2):
			ans += 1
		tim = tim + x
		tim = tim % 1440
	print(ans)
t1 = input()
t = int(t1)
while t > 0:
	sol()
	t = t - 1


def pal(v):
	return int(str(1001 + v % 60 * 10) == str(1001 + v // 60 * 10)[::-1])
p = [0] * 1441
for i in range(1441):
	p[i] = pal(i)
for _ in range(int(input())):
	s = input()
	(s, x) = s.split()
	v = int(s[:2]) * 60 + int(s[3:])
	x = int(x)
	nv = (v + x) % 1440
	ans = p[v]
	while nv != v:
		ans += p[nv]
		nv = (nv + x) % 1440
	print(ans)


t = int(input())
for i in range(t):
	(s, x) = input().split()
	palin = {0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412}
	pal = set()
	minut = (int(s[0]) * 10 + int(s[1])) * 60 + int(s[3]) * 10 + int(s[4])
	for j in range(1440):
		pal.add(minut)
		minut = (minut + int(x)) % 1440
	a_per_b = palin.intersection(pal)
	print(len(a_per_b))


def sol():
	palindrom_time = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	(s, x) = input().split()
	x = int(x)
	time = int(s[:2]) * 60 + int(s[3:])
	stop = time
	count = 0
	while True:
		time = (time + x) % 1440
		if time in palindrom_time:
			count += 1
		if time == stop:
			break
	print(count)
for t in range(int(input())):
	sol()


from functools import lru_cache

@lru_cache(None)
def check_palindrome(num: int):
	(hours, mins) = divmod(num, 60)
	return f'{hours:02d}'[::-1] == f'{mins:02d}'
MAX = 24 * 60

@lru_cache(None)
def check_time(t: int, x: int):
	s = set()
	ans = 0
	while t not in s:
		if check_palindrome(t):
			ans += 1
		s.add(t)
		t = (t + x) % MAX
	return ans

def f():
	(t, x) = input().split()
	(h, m) = map(int, t.split(':'))
	t = h * 60 + m
	x = int(x)
	print(check_time(t, x))
for _ in range(int(input())):
	f()


for _ in range(int(input())):
	(s, a) = input().split()
	a = int(a)
	current = int(s[:2]) * 60 + int(s[3:])
	d_time = current
	m = set()
	palindrome = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	while True:
		if d_time in palindrome:
			m.add(d_time)
		d_time = (d_time + a) % 1440
		if d_time == current:
			break
	print(len(m))


def test():
	s = input()
	h = int(s[0:2])
	m = int(s[3:5])
	x = int(s[6:])
	inh = h
	inm = m
	do = 0
	count = 0
	while (h != inh or m != inm) or do == 0:
		do = 1
		if h % 10 == m // 10 and h // 10 == m % 10:
			count += 1
		carry = (m + x) // 60
		m = (m + x) % 60
		h = (carry + h) % 24
	print(count)
t = int(input())
for i in range(t):
	test()


def is_pal(m: int) -> bool:
	h = m // 60
	m = m % 60
	return h // 10 == m % 10 and h % 10 == m // 10

def solve():
	(s_time, sx) = input().split()
	(h, m) = map(int, s_time.split(':'))
	m = h * 60 + m
	x = int(sx)
	s = set()
	for _ in range(1441):
		if is_pal(m):
			if m in s:
				break
			s.add(m)
		m = (m + x) % 1440
	print(len(s))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import collections
import math
import sys
from queue import PriorityQueue
from random import randint

def main(testnumber):
	(time, x) = input().split()
	x = int(x)
	(h, m) = map(int, time.split(':'))
	m += h * 60
	s = set()
	for i in range(1441):
		m %= 1440
		minutes = m % 60
		hours = m // 60
		minute_rev = minutes % 10 * 10 + minutes // 10
		if hours == minute_rev:
			s.add(hours)
		m += x
	print(len(s))
t = int(input())
cnt = 1
while t > 0:
	main(cnt)
	cnt += 1
	t -= 1


pal = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	count = 0
	l = list(map(str, input().split()))
	(hh, mm) = [int(x) for x in l[0].split(':')]
	x = int(l[1])
	d = 60 * hh + mm
	if d in pal:
		count += 1
	z = (d + x) % 1440
	while z != d:
		if z in pal:
			count += 1
		z = (z + x) % 1440
	print(count)


import sys
try:
	sys.stdin = open('input.txt')
except FileNotFoundError:
	pass
palindromes = []
for i in range(24):
	si = str(i)
	if len(si) == 1:
		si = '0' + si
	m = int(si[1] + si[0])
	if m > 59:
		continue
	palindromes.append(i * 60 + m)
n = int(input())
for i in range(n):
	(s, x) = input().split()
	s = s.split(':')
	x = int(x)
	t = int(s[0]) * 60 + int(s[1])
	tt = t
	p_copy = palindromes.copy()
	ans = 0
	while True:
		tt += x
		tt %= 1440
		if tt in p_copy:
			ans += 1
			p_copy.remove(tt)
		if tt == t:
			break
	print(ans)


import sys

def my_gcd(a, b):
	a_1 = max(a, b)
	b_1 = min(a, b)
	while b_1 != 0:
		a_1 = a_1 % b_1
		(a_1, b_1) = (max(a_1, b_1), min(a_1, b_1))
	return a_1
n = int(sys.stdin.readline())
for i in range(n):
	data = sys.stdin.readline().split()
	step = int(data[1])
	hours = int(data[0][0:2])
	minutes = int(data[0][3:])
	times = 1440 // my_gcd(1440, step)
	number_of_poli = 0
	for t in range(times):
		minutes += step
		hours += minutes // 60
		hours = hours % 24
		minutes = minutes % 60
		if hours // 10 == minutes % 10 and hours % 10 == minutes // 10:
			number_of_poli += 1
	print(number_of_poli)


t = int(input())
for z in range(t):
	(ti, r) = input().split()
	h = ti[0:2]
	m = ti[3:5]
	(h, m, r) = (int(h), int(m), int(r))
	count = 0
	time = h * 60 + m
	li = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	for i in range(1440):
		if (time + i * r) % 1440 in li:
			count += 1
			ind = li.index((time + i * r) % 1440)
			li.pop(ind)
	print(count)


import sys

def isit(h, m):
	m = m % 10 * 10 + int(m / 10)
	return m == h

def solve():
	i = input().split()
	(h, m) = map(int, i[0].split(':'))
	(h1, m1) = (h, m)
	x = int(i[1])
	cnt = 0
	hs = int(x / 60)
	ms = x % 60
	while True:
		if isit(h, m):
			cnt += 1
		h += hs
		h %= 24
		m += ms
		if m > 59:
			m %= 60
			h += 1
			h %= 24
		if h1 == h and m1 == m:
			print(cnt)
			break
t = int(sys.stdin.readline())
for _ in range(t):
	solve()


z = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	(a, b) = input().split()
	(h, m) = map(int, a.split(':'))
	x = 60 * h + m
	b = int(b)
	d = {}
	cnt = 0
	while True:
		if x in d:
			break
		else:
			d[x] = 1
		if x in z:
			cnt += 1
		x = (x + b) % 1440
	print(cnt)


t = int(input())
palindromes = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(t):
	info = input()
	hours = int(info[0:2])
	minutes = int(info[3:5])
	step_size = int(info[6:])
	start_time = hours * 60 + minutes
	time = start_time
	result = 0
	while True:
		time = (time + step_size) % 1440
		if time in palindromes:
			result += 1
		if time == start_time:
			break
	print(result)


t = int(input())
for i in range(t):
	time = input().split()
	hour = int(time[0][0:2])
	minute = int(time[0][3:5])
	initialHour = hour
	initialMinute = minute
	x = int(time[1])
	palindromes = 0
	while True:
		minute += x
		hour += minute // 60
		minute %= 60
		hour %= 24
		if hour == 10 * (minute % 10) + minute // 10:
			palindromes += 1
		if hour == initialHour and minute == initialMinute:
			break
	print(palindromes)


def solution():
	inp = input().split()
	s = list(map(int, inp[0].split(':')))
	i = int(inp[1])
	ih = i // 60
	im = i % 60
	old = s[:]
	count = 0
	while True:
		nm = (old[1] + im) % 60
		nh = (old[0] + ih + (old[1] + im) // 60) % 24
		if nm % 10 == nh // 10 and nm // 10 == nh % 10:
			count += 1
		old = [nh, nm]
		if old[0] == s[0] and old[1] == s[1]:
			break
	print(count)
t = int(input())
while t:
	solution()
	t -= 1


def isp(t):
	h = t // 60
	m = t % 60
	return h // 10 == m % 10 and h % 10 == m // 10
t = int(input())
for _ in range(t):
	(d, i) = input().split()
	(hs, ms) = d.split(':')
	b = int(hs) * 60 + int(ms)
	i = int(i)
	r = 0
	if isp(b):
		r += 1
	c = (b + i) % (24 * 60)
	while c != b:
		if isp(c):
			r += 1
		c = (c + i) % (24 * 60)
	print(r)


t = int(input())
pale = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for j in range(t):
	(a, b) = input().split()
	b = int(b)
	(hh, mm) = map(int, a.split(':'))
	a = hh * 60 + mm
	p = 0
	x = a
	if a in pale:
		p += 1
	a += b
	if a >= 1440:
		a -= 1440
	while a != x:
		if a in pale:
			p += 1
		a += b
		if a >= 1440:
			a -= 1440
	print(p)


def IsP(t):
	(h, m) = (t // 60, t % 60)
	return h // 10 == m % 10 and h % 10 == m // 10
t = int(input())
for _ in range(t):
	(st, p) = input().split()
	p = int(p)
	t = int(st[:2]) * 60 + int(st[3:])
	count = 1 if IsP(t) else 0
	ct = t
	while (ct + p) % (24 * 60) != t:
		ct = (ct + p) % (24 * 60)
		if IsP(ct):
			count += 1
	print(count)


for _ in range(int(input())):
	li = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	(time, minn) = [i for i in input().split(' ')]
	time = time.split(':')
	minn = int(minn)
	sumMinutes = int(time[0]) * 60 + int(time[1])
	minx = sumMinutes
	count = 0
	while True:
		if minx in li:
			count += 1
		minx += minn
		if minx >= 1440:
			minx -= 1440
		if minx == sumMinutes:
			break
	print(count)


pal = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	(time, x) = map(str, input().split())
	hrs = int(time[0:2]) * 60
	x = int(x)
	mins = int(time[3:5])
	total = mins + hrs
	ans = 0
	initial = total
	total %= 1440
	if total in pal:
		ans += 1
	total += x
	total %= 1440
	while total != initial:
		if total in pal:
			ans += 1
		total += x
		total %= 1440
	print(ans)


def isp(t):
	h = t // 60
	m = t % 60
	return h // 10 == m % 10 and h % 10 == m // 10
t = int(input())
while t != 0:
	(d, i) = input().split()
	(hs, ms) = d.split(':')
	b = int(hs) * 60 + int(ms)
	i = int(i)
	r = 0
	if isp(b):
		r += 1
	c = (b + i) % (24 * 60)
	while c != b:
		if isp(c):
			r += 1
		c = (c + i) % 1440
	print(r)
	t -= 1


import math
for fuckfuckfuckfuckfuckfuckfuck in range(int(input())):
	(x, y) = input().split()
	oz = 0
	y = int(y)
	y = math.gcd(1440, y)
	(w, z) = map(int, x.split(':'))
	v = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	u = w * 60 + z
	for fucktheclock in range(1440 // y):
		u = u + y
		if u >= 1440:
			u = u - 1440
		if u in v:
			oz = oz + 1
	print(oz)


def check():
	smth = [str(i) for i in input().split()]
	s = smth[0]
	x = int(smth[1])
	b = set()
	counter = 0
	first = int(s[0] + s[1])
	second = int(s[3] + s[4])
	b.add((first, second))
	while True:
		second += x
		if second > 59:
			first += second // 60
			first %= 24
			second %= 60
		if (first, second) in b:
			break
		else:
			b.add((first, second))
	for i in b:
		if i[0] // 10 == i[1] % 10 and i[0] % 10 == i[1] // 10:
			counter += 1
	return counter
t = int(input())
for i in range(t):
	print(check())


for _ in range(int(input())):
	a = [0, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 70, 140, 210, 280, 350, 1412]
	(n, m) = input().split()
	(n, m) = (int(n[:2]) * 60 + int(n[3:]), int(m))
	c = 0
	for i in range(24 * 60):
		n = (n + m) % 1440
		if n in a:
			a.remove(n)
			c += 1
			if c == 16:
				break
	print(c)


def add_time(t, h, m):
	m += t
	h += m // 60
	m = m % 60
	h = h % 24
	return (h, m)

def is_pal(h, m):
	return h // 10 == m % 10 and h % 10 == m // 10
n = int(input())
for i in range(n):
	(time, t) = input().split()
	t = int(t)
	(h, m) = time.split(':')
	h = int(h)
	m = int(m)
	(old_h, old_m) = (h, m)
	k = 0
	if is_pal(h, m):
		k += 1
	(h, m) = add_time(t, h, m)
	while h != old_h or m != old_m:
		if is_pal(h, m):
			k += 1
		(h, m) = add_time(t, h, m)
	print(k)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(s, x) = input().split()
	x = int(x)
	s = list(map(int, s.split(':')))
	count = 0
	palindrome = {(0, 0), (10, 1), (20, 2), (1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (13, 31), (14, 41), (15, 51), (11, 11), (12, 21), (22, 22), (21, 12), (23, 32)}
	(m, h) = (s[1], s[0])
	org = (h, m)
	while True:
		if (h, m) in palindrome:
			count += 1
		m += x
		h += m // 60
		h %= 24
		m %= 60
		if org == (h, m):
			break
	print(count)


import sys
input = sys.stdin.readline

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

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

def S():
	return input().rstrip()
sys.setrecursionlimit(10 ** 6)
INF = 1 << 60
t = int(input())
for _ in range(t):
	s = S()
	h = int(s[0] + s[1])
	m = int(s[3] + s[4])
	x = int(s[6:])
	check = set()
	if h // 10 == m % 10 and h % 10 == m // 10:
		ans = 1
		check.add(h)
	else:
		ans = 0
	for i in range(1441):
		m += x
		tmp = m // 60
		m %= 60
		h += tmp
		h %= 24
		if h in check:
			continue
		if h // 10 == m % 10 and h % 10 == m // 10:
			ans += 1
			check.add(h)
	print(ans)


t = int(input())
palindrome = [0, 70, 140, 210, 280, 350, 671, 1342, 601, 1202, 741, 811, 881, 951, 1272, 1412]
while t:
	(n, x) = map(str, input().split())
	x = int(x)
	temp = n[0] + n[1]
	temp1 = n[3] + n[4]
	sati = int(temp)
	minute = int(temp1)
	kraj = False
	cnt = 0
	minute += sati * 60
	pocetak = minute + 0
	while 1:
		minute += x
		minute %= 1440
		if minute in palindrome:
			cnt += 1
		if minute == pocetak:
			kraj = True
		if kraj:
			break
	print(cnt)
	t -= 1


for _ in range(int(input())):
	(s, x) = [x for x in input().split()]
	l = set([0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412])
	if False:
		print('Tanmay')
	x = int(x)
	t = int(s[3:]) + int(s[:2]) * 60
	c = 0
	z = t
	a = set()
	z = t - x
	while z >= 0:
		a.add(z)
		z -= x
	while z < 1440:
		a.add(z)
		z += x
	while True:
		if z % 1440 in a:
			break
		a.add(z % 1440)
		z += x
	for i in set(a):
		if i in l:
			c += 1
	print(c)


pal = [0, 1001, 110, 1111, 2002, 220, 2222, 1221, 2112, 1331, 2332, 1441, 1551, 330, 440, 550]
tpal = [60 * (x // 100) + x % 100 for x in pal]
tpal.sort()
for t in range(int(input())):
	(start, period) = input().split()
	(hh, mm) = map(int, start.split(':'))
	p = int(period)
	count = 0
	st1 = (hh * 60 + mm) % 1440
	if tpal.count(st1) == 1:
		count += 1
	st = (st1 + p) % 1440
	while st != st1:
		if tpal.count(st) == 1:
			count += 1
		st += p
		st = st % 1440
	print(count)


for _ in range(int(input())):
	s = input()
	hr = s[0:2]
	mn = s[3:5]
	x = s[6:]
	hr = int(hr)
	mn = int(mn)
	x = int(x)
	t = hr * 60 + mn
	valid = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	ans = []
	ans.append(t)
	temp = (t + x) % 1440
	ans.append(temp)
	while temp != t:
		temp += x
		if temp >= 1400:
			temp = temp % 1440
		ans.append(temp)
	ans = list(set(ans))
	cnt = 0
	for x in ans:
		if x in valid:
			cnt += 1
	print(cnt)


arr = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]

def minutes(s):
	(x, y) = s.split(':')
	return int(x) * 60 + int(y)
for _ in range(int(input())):
	(t, x) = input().split(' ')
	x = int(x)
	m = minutes(t)
	ans = 0
	s = [0] * 16
	for __ in range(1440):
		m += x
		m = m % 1440
		if m in arr and s[arr.index(m)] == 0:
			s[arr.index(m)] += 1
			ans += 1
	print(ans)


for _ in range(int(input())):
	s = input()
	h = int(s[:2])
	m = int(s[3:5])
	x = int(s[6:])
	t = h * 60 + m
	pal = set()
	for i in range(1440):
		h = t // 60 % 24
		m = t % 60
		if h // 10 == m % 10 and h % 10 == m // 10:
			if (h, m) in pal:
				break
			pal.add((h, m))
		t += x
	print(len(pal))


pal_min = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	(t, x) = input().split()
	(h, m) = map(int, t.split(':'))
	minutes = m + h * 60
	ans = 0
	set_ = set()
	for i in range(1440):
		set_.add(minutes)
		minutes = (minutes + int(x)) % 1440
	for i in pal_min:
		if i in set_:
			ans += 1
	print(ans)


prelist = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	a = list()
	l = input().split()
	l[1] = int(l[1])
	(starth, startm) = map(int, l[0].split(':'))
	ans = 0
	hh = starth * 60 + startm
	while True:
		if hh in prelist:
			ans += 1
		hh += l[1]
		if hh >= 60 * 24:
			hh -= 1440
		if hh == starth * 60 + startm:
			break
	print(ans)


a = [0]
for i in range(1, 6):
	a.append(i * 60 + i * 10)
for i in range(10, 16):
	a.append(i * 60 + int(str(i)[::-1]))
for i in range(20, 24):
	a.append(i * 60 + int(str(i)[::-1]))
t = int(input())
for _ in range(t):
	(s, x) = input().split()
	x = int(x)
	c = int(s[:2]) * 60 + int(s[3:])
	if x + c >= 1440:
		b = x + c - 1440
	else:
		b = x + c
	ans = 0
	if c in a:
		ans = 1
	while b != c:
		if b in a:
			ans += 1
		if x + b >= 1440:
			b += x - 1440
		else:
			b += x
	print(ans)


for i in range(int(input())):
	(time, p) = input().split()
	(p_h, p_m) = divmod(int(p), 60)
	(h, m) = map(int, time.split(':'))
	(t_h, t_m) = (h, m)
	first = True
	cnt = 0
	while first or h != t_h or m != t_m:
		first = False
		if t_h // 10 == t_m % 10 and t_h % 10 == t_m // 10:
			cnt += 1
		t_h = (t_h + p_h + (t_m + p_m) // 60) % 24
		t_m = (t_m + p_m) % 60
	print(cnt)


n = int(input())
for i in range(n):
	lst = list(input().split())
	increase = int(lst[1])
	all = set()
	if lst[1] == '1440':
		if lst[0][0] == lst[0][-1] and lst[0][1] == lst[0][-2]:
			print(1)
		else:
			print(0)
	else:
		num1 = 0
		num2 = 0
		if lst[0][0] == '0':
			num2 += int(lst[0][1])
		else:
			num2 += int(lst[0][0] + lst[0][1])
		if lst[0][-2] == '0':
			num1 += int(lst[0][-1])
		else:
			num1 += int(lst[0][-2] + lst[0][-1])
		for j in range(1440):
			num1 += increase % 60
			num2 += increase // 60
			if num1 > 59:
				num2 += 1
				num1 -= 60
			if num2 > 23:
				num2 -= 24
			if num2 % 10 == num1 // 10 and num2 // 10 == num1 % 10:
				all.add(num1)
		print(len(all))


def ispal(t):
	m = t % 60
	m1 = m // 10
	m2 = m % 10
	h = t // 60
	h1 = h // 10
	h2 = h % 10
	return m1 == h2 and m2 == h1
t = int(input())
for i in range(t):
	(st, smin) = input().split()
	smin = int(smin)
	time = int(st[:2]) * 60 + int(st[3:])
	t0 = time
	count = 0
	if ispal(time):
		count += 1
	time = (time + smin) % 1440
	while time != t0:
		if ispal(time):
			count += 1
		time = (time + smin) % 1440
	print(count)


t = int(input())
for _ in range(t):
	s = input()
	h0 = int(s[:2])
	m0 = int(s[3:5])
	x = int(s[6:])
	(t0, t) = (h0 * 60 + m0, (h0 * 60 + m0 + x) % 1440)
	ans = 0
	if h0 % 10 == m0 // 10 and h0 // 10 == m0 % 10:
		ans += 1
	while t != t0:
		(h, m) = (t // 60, t % 60)
		if h % 10 == m // 10 and h // 10 == m % 10:
			ans += 1
		t += x
		t %= 1440
	print(ans)


from math import ceil

def solution(h, m, min_delta):

	def plus_time(h, m, min_delta):
		m += min_delta
		h += m // 60
		m %= 60
		h %= 24
		return (h, m)

	def is_palindrome(h, m):
		if h // 10 == m % 10 and h % 10 == m // 10:
			return True
	i = 1
	ans = 0
	time = ()
	while time != (h, m):
		time = plus_time(h, m, min_delta * i)
		if is_palindrome(*time):
			ans += 1
		i += 1
	return ans
for i in range(int(input())):
	(time, min_delta) = input().split()
	(h, m) = time.split(':')
	print(solution(int(h), int(m), int(min_delta)))


t = int(input())
while t:
	(time, s) = input().split()
	(time_hour, time_min) = time.split(':')
	time_hour = int(time_hour)
	time_min = int(time_min)
	(origianl_hour, original_min) = (time_hour, time_min)
	s = int(s)
	count = 0
	time_done = 0
	app = []
	while True:
		if time_hour == origianl_hour and time_min == original_min and (time_done != 0):
			break
		if time_min == time_hour % 10 * 10 + time_hour // 10:
			count += 1
		time_min += s
		hour_rem = time_min // 60
		time_min %= 60
		time_hour += hour_rem
		time_hour %= 24
		time_done += 1
	print(count)
	t -= 1


T = int(input())
while T:
	T -= 1
	N = 1440
	arr = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	arr.sort()
	(a, b) = input().split()
	b = int(b)
	(h, m) = a.split(':')
	x = int(h) * 60 + int(m)
	se = set()
	ans = 0
	while True:
		if len(se) == 0:
			se.add(x)
			if x in arr:
				ans += 1
			x += b
			x %= N
		elif x in se:
			break
		else:
			se.add(x)
			if x in arr:
				ans += 1
			x += b
			x %= N
	print(ans)


def gcd(aa, bb):
	return bb if aa == 0 else gcd(bb % aa, aa)

def lcm(first_num: int, second_num: int) -> int:
	return first_num // gcd(first_num, second_num) * second_num
numbers = (0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412)
for x in range(int(input())):
	(a, b) = input().split()
	b = int(b)
	(c, d) = [int(y) for y in a.split(':')]
	time = c * 60 + d
	common = lcm(1440, b)
	times = common // b
	set_of_times = []
	for y in range(times + 1):
		set_of_times.append((time + y * b) % 1440)
	n = sum((el in numbers for el in set(set_of_times)))
	print(n)
pass


t = int(input())
for i in range(t):
	(s, minutes) = input().split()
	minutes = int(minutes)
	palindrome = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	curr_minutes = 0
	curr_minutes += int(s.split(':')[0]) * 60
	curr_minutes += int(s.split(':')[1])
	cnt = 0
	i = 0
	st = set()
	while i <= 1440:
		curr_minutes += minutes
		curr_minutes %= 1440
		st.add(curr_minutes)
		i += 1
	for i in st:
		if i in palindrome:
			cnt += 1
	print(cnt)


t = int(input())
c = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for l in range(t):
	(a, b) = [i for i in input().split()]
	b = int(b)
	a = [int(i) for i in a.split(':')]
	a = a[0] * 60 + a[1]
	cnt = 0
	a1 = set()
	for i in range(2022):
		a1.add(a)
		a += b
		a %= 1440
	for i in a1:
		if i in c:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(time, x) = input().split()
	(mm, ss) = map(int, time.split()[0].split(':'))
	x = int(x)
	tt = mm * 60 + ss
	tt2 = tt
	ans = 0
	bad = False
	while not bad:
		m = tt2 // 60
		s = tt2 % 60
		if m == s % 10 * 10 + s // 10:
			ans += 1
		tt2 += x
		tt2 %= 1440
		if tt2 == tt:
			bad = True
	print(ans)


p = []
for h in range(24):
	for m in range(60):
		s = ('0' if h < 10 else '') + str(h) + ':' + ('0' if m < 10 else '') + str(m)
		p += (s == s[::-1],)
t = int(input())
for _ in range(t):
	(t, x) = input().split()
	(h, m) = map(int, t.split(':'))
	x = int(x)
	t = 60 * h + m
	nh = h
	nm = m
	b = 0
	cnt = 0
	while (nh, nm) != (h, m) or b == 0:
		nm += x
		nh += nm // 60
		nm %= 60
		nh %= 24
		cnt += p[60 * nh + nm]
		b = 1
	print(cnt)


for _ in range(int(input())):
	i = input()
	(mm, ss) = map(int, i.split()[0].split(':'))
	x = int(i.split()[1])
	tt = mm * 60 + ss
	t = tt
	cnt = 0
	flag = False
	while not flag:
		m = t // 60
		s = t % 60
		if m == s % 10 * 10 + s // 10:
			cnt += 1
		t += x
		t %= 1440
		if t == tt:
			flag = True
	print(cnt)


for t in range(int(input())):
	s = input().split()
	s[0] = s[0].split(':')
	hs = int(s[0][0])
	mins = int(s[0][1])
	x = int(s[1])
	pals = [[0, 0], [1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [10, 1], [11, 11], [12, 21], [13, 31], [14, 41], [15, 51], [20, 2], [21, 12], [22, 22], [23, 32]]
	hs_now = hs
	mins_now = mins
	if x == 1440 and [hs, mins] in pals:
		print(1)
	else:
		k = 0
		if [hs, mins] in pals:
			k += 1
			pals.pop(pals.index([hs, mins]))
		mins_now = mins
		hs_now = hs
		mins_now += x
		hs_now += mins_now // 60
		mins_now %= 60
		hs_now %= 24
		while hs_now != hs or mins_now != mins:
			if [hs_now, mins_now] in pals:
				k += 1
				pals.pop(pals.index([hs_now, mins_now]))
			mins_now += x
			hs_now += mins_now // 60
			mins_now %= 60
			hs_now %= 24
		print(k)


def str_int(a):
	return int(a[0]) * 10 + int(a[1])

def is_palin(a, b):
	if a == b % 10 * 10 + b // 10:
		return True
	else:
		return False

def min_to_str(a):
	hh = a // 60 % 24
	mm = a % 60
	return is_palin(hh, mm)
t = int(input())
while t > 0:
	t -= 1
	a = input().split()
	x = int(a[1])
	b = a[0].split(':')
	hh = str_int(b[0])
	mm = str_int(b[1])
	minuts = hh * 60 + mm
	y = (minuts + x) % 1440
	s = 0
	while y != minuts:
		if min_to_str(y):
			s += 1
		y += x
		y = y % 1440
	if min_to_str(minuts):
		s += 1
	print(s)


for p in range(int(input())):
	(s, x) = input().split()
	x = int(x)
	pals = set()
	hours = ['0' + str(i) for i in range(10)] + [str(i) for i in range(10, 24)]
	mins = ['0' + str(i) for i in range(10)] + [str(i) for i in range(10, 60)]
	t_h = int(s[0] + s[1])
	t_m = int(s[3] + s[4])
	s0 = hours[t_h] + mins[t_m]
	t0 = t_h * 60 + t_m
	if s0 == s0[::-1]:
		pals.add(s0)
	ntime = (t_h * 60 + t_m + x) % (60 * 24)
	while ntime != t0:
		n_h = ntime // 60
		n_m = ntime % 60
		s_n = hours[n_h] + mins[n_m]
		if s_n == s_n[::-1]:
			pals.add(s_n)
		ntime = (ntime + x) % (60 * 24)
	print(len(pals))


for _ in range(int(input())):
	arr = input().split()
	a = arr[0]
	b = int(arr[1])
	cnt = 0
	reva = a[::-1]
	if a == reva:
		cnt += 1
	(h, m) = (b // 60, b % 60)
	(lx, rx) = (int(a[:2]), int(a[3:]))
	lx1 = lx
	rx1 = rx
	lx += h
	rx += m
	if rx > 59:
		lx += 1
		rx -= 60
	if lx > 23:
		lx -= 24
	while lx != lx1 or rx1 != rx:
		if lx // 10 == rx % 10 and lx % 10 == rx // 10:
			cnt += 1
		lx += h
		rx += m
		if rx > 59:
			lx += 1
			rx -= 60
		if lx > 23:
			lx -= 24
	print(cnt)


pal = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	data = input()
	hr = int(data[:2]) * 60
	mn = int(data[3:5])
	gm = hr + mn
	am = int(data[6:])
	i = 1
	count = 0
	while True:
		cm = gm + i * am
		if cm >= 24 * 60:
			cm = cm % (24 * 60)
		if cm in pal:
			count += 1
		if cm == gm:
			break
		i += 1
	print(count)


import sys
input = sys.stdin.readline

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

def inlt():
	return list(map(int, input().split()))
n = inp()
palindromes = {0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412}
for _ in range(n):
	(time, minutesToAdd) = input().strip().split(' ')
	time = time.split(':')
	timeInMinutes = int(time[0]) * 60 + int(time[1])
	seen = set()
	count = 0
	while timeInMinutes not in seen:
		seen.add(timeInMinutes)
		if timeInMinutes in palindromes:
			count += 1
		timeInMinutes += int(minutesToAdd)
		if timeInMinutes >= 1440:
			timeInMinutes -= 1440
	print(count)


import re
pali_clk = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
for _ in range(int(input())):
	a = input()
	a = re.split(':| ', a)
	num = 0
	now = int(a[0]) * 60 + int(a[1])
	current = now
	while True:
		if current in pali_clk:
			num += 1
		current = (current + int(a[2])) % 1440
		if current == now:
			break
	print(num)


l = {0: 0, 1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 10: 1, 11: 11, 12: 21, 13: 31, 14: 41, 15: 51, 20: 2, 21: 12, 22: 22, 23: 32}
t = int(input())
for _ in range(t):
	k = input().split(' ')
	t = int(k[1])
	(h, m) = map(int, k[0].split(':'))
	hi = h
	mi = m
	d = 0
	th = t // 60
	tm = t % 60
	if l.get(h, -1) == m:
		d += 1
	while True:
		r = (m + tm) // 60
		m = (m + tm) % 60
		h = h + th + r
		if h > 23:
			h -= 24
		if h == hi and m == mi:
			break
		if l.get(h, -1) == m:
			d += 1
	print(d)


for t in range(int(input())):
	(s, k) = input().split()
	palindrome = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
	m = int(s[:2]) * 60 + int(s[3:])
	m_list = set()
	seen = set()
	while m not in seen:
		if m in palindrome:
			m_list.add(m)
		seen.add(m)
		m = (m + int(k)) % 1440
	print(len(m_list))


def the_clock(s):
	(t, x) = input().split()
	x = int(x)
	t = list(map(int, t.split(':')))
	(t1, t2) = t
	h = x // 60
	m = x % 60
	count = 0
	while True:
		t[0] += h
		t[1] += m
		if t[1] >= 60:
			t[0] += 1
			t[1] -= 60
		if t[0] >= 24:
			t[0] -= 24
		if (t[0], t[1]) in s:
			count += 1
		if t[0] == t1 and t[1] == t2:
			break
	return count
n = int(input())
s = set()
for i in range(6):
	s.add((i, i * 10))
for i in range(10, 16):
	s.add((i, int(str(i)[::-1])))
for i in range(20, 25):
	s.add((i, int(str(i)[::-1])))
for i in range(n):
	print(the_clock(s))


from math import gcd
t = int(input())

def add_minutes(hour, minute, add):
	hour = (hour + (minute + add) // 60) % 24
	minute = (minute + add) % 60
	return (hour, minute)

def is_palindrome(hour, minute):
	return hour % 10 == minute // 10 and hour // 10 == minute % 10
for _ in range(t):
	(time, add) = input().split()
	(hour, minute) = map(int, time.split(':'))
	add = int(add)
	output = 0
	repeat = 24 * 60 // gcd(24 * 60, add)
	for i in range(repeat):
		if is_palindrome(hour, minute):
			output += 1
		(hour, minute) = add_minutes(hour, minute, add)
	print(output)


t = int(input())
palindromes = [0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412]
while t > 0:
	(time, mins) = list(map(str, input().split(' ')))
	mins = int(mins)
	(hh, mm) = list(map(int, time.split(':')))
	total = hh * 60 + mm
	t_set = set()
	for _ in range(2000):
		t_set.add(total)
		total += mins
		total %= 1440
	count = 0
	for minutes in t_set:
		if minutes in palindromes:
			count += 1
	print(count)
	t -= 1


for _ in range(int(input())):
	(s, x) = input().split()
	x = int(x)
	(h, m) = map(int, s.split(':'))
	t = h * 60 + m
	cnt = 0
	while True:
		t += x
		(h1, m1) = divmod(t, 60)
		h1 %= 24
		(a, b) = divmod(h1, 10)
		(c, d) = divmod(m1, 10)
		cnt += a == d and b == c
		if h1 == h and m1 == m:
			break
	print(cnt)


import sys
input = sys.stdin.readline

def A():
	return [int(i) for i in input().split()]

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

def solve():
	(n, t) = input().split()
	t = int(t)
	(x1, x2) = map(int, n.split(':'))
	ans = 0
	o1 = x1
	o2 = x2
	while 1:
		x2 += t % 60
		if x2 >= 60:
			x1 += 1
		x2 %= 60
		x1 += t // 60
		x1 %= 24
		c2 = str(x2)
		c1 = str(x1)
		if x1 < 10:
			c1 = '0' + c1
		if x2 < 10:
			c2 = '0' + c2
		if c1 == c2[::-1]:
			ans += 1
		if x1 == o1 and x2 == o2:
			return ans
t = inp()
for _ in range(t):
	print(solve())


def solve():
	(s, x) = input().split()
	x = int(x)
	if x == 1:
		print('16')
		return
	(hh, mm) = (x // 60, x % 60)
	(sth, stm) = map(int, s.split(':'))
	(ith, itm) = (sth, stm)
	ans = 0
	while True:
		sth = (sth + hh + (stm + mm) // 60) % 24
		stm = (stm + mm) % 60
		ssth = str(sth) if sth >= 10 else f'0{sth}'
		sstm = str(stm) if stm >= 10 else f'0{stm}'
		ssthm = f'{ssth}:{sstm}'
		if ssthm == ssthm[::-1]:
			ans += 1
		if sth == ith and stm == itm:
			break
	print(ans)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	[hhmm, k] = input().split(' ')
	k = int(k)
	[hh, mm] = list(map(int, hhmm.split(':')))
	st = set()
	ans = 0
	[dh, dm] = [k // 60, k % 60]
	while True:
		if st.__contains__(hh * 100 + mm):
			break
		else:
			st.add(hh * 100 + mm)
		if hh // 10 == mm % 10 and hh % 10 == mm // 10:
			ans += 1
		mm += dm
		hh += dh
		if mm >= 60:
			hh += 1
		mm %= 60
		hh %= 24
	print(ans)


for _ in range(int(input())):
	(s, x) = input().split()
	x = int(x)
	(h, m) = map(int, s.split(':'))
	time = h * 60 + m
	count = 0
	i = 0
	while True:
		time += x
		(h1, m1) = divmod(time, 60)
		h1 %= 24
		(a, b) = divmod(h1, 10)
		(c, d) = divmod(m1, 10)
		count += a == d and b == c
		if h1 == h and m1 == m:
			break
		i += 1
	print(count)


def clock_looking(start_time, check_interval):
	curr_time = start_time
	curr_minute = time_to_minute(curr_time)
	seen = set()
	palindrome_times = set()
	while curr_minute not in seen:
		if curr_time == curr_time[::-1]:
			palindrome_times.add(curr_time)
		seen.add(curr_minute)
		curr_minute = (curr_minute + check_interval) % 1440
		curr_time = minute_to_time(curr_minute)
	return len(palindrome_times)

def time_to_minute(time):
	(hour, minute) = tuple(map(int, time.split(':')))
	return hour * 60 + minute

def minute_to_time(minute):
	(hour, minute) = (minute // 60, minute % 60)
	return '%02d:%02d' % (hour, minute)
num_test_cases = int(input())
for _ in range(num_test_cases):
	(start_time, check_interval) = input().split()
	check_interval = int(check_interval)
	print(clock_looking(start_time, check_interval))


def solve(hi, mi, x):
	(hm, mm) = (hi, mi)
	(ha, ma) = (x // 60, x % 60)
	c = 0
	minutes = x
	while 1:
		if str(hm).zfill(2) == str(mm).zfill(2)[::-1]:
			c += 1
		mm += ma
		hm += ha
		if mm >= 60:
			hm += 1
			mm = mm % 60
		if hm >= 24:
			hm = hm % 24
		minutes += x
		if hi == hm and mi == mm:
			break
	return c
t = int(input())
for _ in range(t):
	_input = input().split()
	(hi, mi) = [int(x) for x in _input[0].split(':')]
	x = int(_input[1])
	print(solve(hi, mi, x))


DAY = 24 * 60

def solve(hour, minute, interval):
	time = hour * 60 + minute
	seen = set()
	while time not in seen:
		seen.add(time)
		time += interval
		time %= DAY
	return sum(map(check_palindrome, seen))

def check_palindrome(time):
	(hour, minute) = divmod(time, 60)
	return f'{hour:02d}' == f'{minute:02d}'[::-1]
for _ in range(int(input())):
	(time_str, interval_str) = input().split()
	(hour, minute) = map(int, time_str.split(':'))
	print(solve(hour, minute, int(interval_str)))


import math
M = 1440
for s in [*open(0)][1:]:
	((h, m), (x,)) = (map(int, u.split(':')) for u in s.split())
	m += h * 60
	print(sum((t == t[::-1] for t in (f'{t % M // 60:02}{t % 60:02}' for t in range(m, m + M, math.gcd(x, M))))))


def gettime(n):
	return '%02d:%02d' % (n // 60, n % 60)
for _ in range(int(input())):
	(s, n) = input().split()
	n = int(n)
	cnt = 0
	if s == s[::-1]:
		cnt += 1
	(h, m) = map(int, s.split(':'))
	time = h * 60 + m
	T = time
	time += n
	time %= 1440
	while time != T:
		s = gettime(time)
		if s == s[::-1]:
			cnt += 1
		time += n
		time %= 1440
	print(cnt)


def rev(x):
	if x < 10:
		return x * 10
	r = 0
	while x > 0:
		r *= 10
		r += x % 10
		x //= 10
	return r
for test in range(int(input())):
	(s, d) = input().split()
	(h, m) = map(int, s.split(':'))
	d = int(d)
	un = set()
	ans = 0
	while True:
		hh = (m + d) // 60
		h = (h + hh) % 24
		m = (m + d) % 60
		if (h, m) in un:
			break
		if h == rev(m):
			ans += 1
		un.add((h, m))
	print(ans)


from collections import defaultdict
from math import gcd

def get_time(v):
	return '%02d:%02d' % (v // 60, v % 60)

def lcm(a, b):
	return a // gcd(a, b) * b
for _ in range(int(input())):
	(time_s, d) = input().split()
	d = int(d)
	(h, m) = map(int, time_s.split(':'))
	cur = h * 60 + m
	ans = 0
	las = cur + lcm(1440, d)
	for ti in range(cur, las, d):
		time_s = get_time(ti % 1440)
		if time_s == time_s[::-1]:
			ans += 1
	print(ans)


n = int(input())
for x in range(n):
	(time, freq) = input().split()
	freq = int(freq)
	time = list(map(int, time.split(':')))
	seen = [time]
	cnt = 0
	if time[0] // 10 == time[1] % 10 and time[0] % 10 == time[1] // 10:
		cnt += 1
	while True:
		time = [(time[0] + freq // 60 + (time[1] + freq % 60) // 60) % 24, (time[1] + freq % 60) % 60]
		if time[0] == seen[0][0] and time[1] == seen[0][1]:
			break
		seen.append(time)
		if time[0] // 10 == time[1] % 10 and time[0] % 10 == time[1] // 10:
			cnt += 1
	print(cnt)


t = int(input())
for q in range(t):
	a = input()
	(h, m) = map(int, a[:5].split(':'))
	(hh, mm) = (h, m)
	r = int(a[6:])
	cnt = 0
	hh = (hh + (mm + r) // 60) % 24
	mm = (mm + r) % 60
	if f'{hh:02}' == f'{mm:02}'[::-1]:
		cnt += 1
	while h != hh or m != mm:
		hh = (hh + (mm + r) // 60) % 24
		mm = (mm + r) % 60
		if f'{hh:02}' == f'{mm:02}'[::-1]:
			cnt += 1
	print(cnt)