Fair and Square (Small)

Count numbers in each interval [A, B] that are palindromes and squares of palindromes.

Easy2Brute forceMathStringInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

An integer that reads the same forwards and backwards is a palindrome. 6, 11 and 121 are palindromes, while 10, 12, 223 and 2244 are not. Leading zeroes do not count when you decide whether a number is a palindrome, even though 010 equals 10.

Call a number fair and square when it is a palindrome and also the square of a palindrome. 1, 9 and 121 are fair and square: each one is a palindrome, and they are the squares of 1, 3 and 11, which are palindromes too. 16, 22 and 676 are not fair and square. 16 is not a palindrome, 22 is not a square, and 676 is both a palindrome and a square but it is the square of 26, which is not a palindrome.

Given one interval, count the fair and square numbers inside it.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers AA and BB, separated by a space, the endpoints of one interval.

Limits

  • 1T1001 \le T \le 100
  • 1AB10001 \le A \le B \le 1000

Output

For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is how many fair and square numbers are greater than or equal to AA and less than or equal to BB.