public static void main(String[] args) throws FileNotFoundException {
        int t;
        System.setIn(new FileInputStream("in.small"));
        Scanner in = new Scanner(System.in);
        t = in.nextInt();
        List<Long> palindrome = new ArrayList<Long>();
        for (long i = 1; i <= 10000000; i++) {
            if (isPalindrome(String.valueOf(i)))
                palindrome.add(i);
        }
        for (int c = 1; c <= t; c++) {
            long a = in.nextLong();
            long b = in.nextLong();
            int count = 0;
            for (long i : palindrome) {
                long sqrSum = i * i;
                if (sqrSum > b)
                    break;
                if (sqrSum >= a && isPalindrome(String.valueOf(sqrSum))) {
                    count++;
                }
            }
            System.out.println(String.format("Case #%d: %d", c, count));
        }
    }