import sys

def is_palindrome(n):
    n_s = str(n)
	return n_s == n_s[::-1]

fs_list = [1, 4, 9, 121, 484]
fs_sqrt_list = [[], [1, 2, 3], [11, 22]]

for n in range(3, 100 / 2 + 1):
	fs_sqrt_list.append([])
	half_n = n / 2
	is_n_odd = (half_n + half_n != n)
	
	if is_n_odd:
		ref_index = n - 1
		insert_s_list = ["0", "1", "2"]
	else:
		ref_index = n - 2
		insert_s_list = ["00", "11"]
	
	for val in fs_sqrt_list[ref_index]:
		s = str(val)
		half_s = s[:len(s) / 2]
		half_s_rev = half_s[::-1]
		
		if half_s[0] == '2':
			insert_s_list.pop()
		
		for insert_s in insert_s_list:
			fs_sqrt_candidate = int(half_s + insert_s + half_s_rev)
			fs_candidate = fs_sqrt_candidate ** 2
			
			if is_palindrome(fs_candidate):
				fs_list.append(fs_candidate)
				fs_sqrt_list[n].append(fs_sqrt_candidate)

case_cnt = int(sys.stdin.readline());

for t in range(1, case_cnt + 1):
	line = sys.stdin.readline();
	start, end = map(int, line.split(' '));
	fs_cnt = len([n for n in fs_list if n >= start and n <= end])
	print "Case #%d: %d" % (t, fs_cnt)
	