import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Recycle {

	private static HashMap<Integer, HashSet<Integer>> map = new HashMap<Integer, HashSet<Integer>>();
	private static HashSet<Integer> toSkip = new HashSet<Integer>();
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int T = reader.nextInt();
		for (int tc = 1; tc <= T; tc++) {
			int a = reader.nextInt();
			int b = reader.nextInt();
			long before = System.currentTimeMillis();
			int res = doit(a, b);
			System.out.printf("Case #%d: %d\n", tc, res);
			long after = System.currentTimeMillis();
//			System.out.println("time taken: " + (after - before));
		}
	}

	private static int doit(int a, int b) {
		int count = 0;
		HashSet<Integer> skip = new HashSet<Integer>(toSkip);
		for (int i = a; i <= b; i++) {
			if (skip.contains(i))
				continue;
			HashSet<Integer> arr = generate(i);
//			if(arr.size() > 1) {
//				map.put(i, arr);
//			}
			// System.out.println(i + " --> " +
			// Arrays.deepToString(arr.toArray()));
			int temp = 0;
			if (arr.size() > 1) {
				for (int x : arr) {
					if (x >= a && x <= b) {
						temp++;
						skip.add(x);
					}
				}
				count += temp * (temp - 1) / 2;
			}
//			System.out.println("not skipping " + i + " gen: " + arr.size()+ " " + (temp * (temp - 1) / 2));
		}
		return count;
	}

	private static HashSet<Integer> generate(int num) {
		if(map.containsKey(num)) {
			HashSet<Integer> list = map.get(num);
			return list;
		}
		HashSet<Integer> list = new HashSet<Integer>();
		String s = "" + num;
		list.add(num);
		int len = s.length();
		for (int i = 1; i < len; i++) {
			String temp = s.substring(i) + s.substring(0, i);
			// System.out.println("temp: " + temp);
			if (temp.charAt(0) == '0')
				continue;
			int x = Integer.parseInt(temp);
			if( x <= 2000000) {
				list.add(x);
			}
		}
		if(list.size() > 1) {
			map.put(num, list);
		} else {
			toSkip.add(num);
		}
		return list;
	}

}

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;


public class C {

	Scanner in;
	public C()
	{
		in = new Scanner(System.in);
		int t = in.nextInt();               // number of test cases ...:)
		for(int l=1;l<=t;l++)
		{
			int n = in.nextInt();           // got n 
            
			int m = in.nextInt();           // got m
			
			int temp=0;                     // For Every data set it has to change 
			int temp2=0;
			int reverse=0;
			int reverse2=0;
			int count=0;
			
			if(n>=10 &&m<100)
			{
				for(int i=n;i<=m;i++)
				{
					temp=i;
					while( temp != 0 )
				      {
				          reverse = reverse * 10;
				          reverse = reverse +temp%10;
				          temp = temp/10;
				      }
					
					
					
					
					if((reverse>=n)&&(reverse<=m)&&(reverse!=i))
					{
						count++;
						
					}
					reverse=0;
				
				}
				
				count=count/2;
			}
			if(n>99 && m<=1000)
			{
				for(int i=n;i<=m;i++)
				{
					 temp=temp2=i;
					
				     
				     reverse = reverse +temp%10;
				     reverse2 = reverse2+temp%100;
				     temp = temp/10;
				     temp2=temp2/100;
				     reverse = (reverse * 100)+temp;      //one position replaced 
				     reverse2= (reverse2*10)+temp2;       //two position interchange
					
					 
					
					if((reverse>=n)&&(reverse<=m)&&(reverse!=i))
						
					{
						count++;
					}
					reverse=0;
					
                    if((reverse2>=n)&&(reverse2<=m)&&(reverse2!=i))
						
					{
						count++;
					}
					reverse2=0;
				
			}
				count=count/2;
		}
			System.out.printf("Case #%d: %d\n", l,count);
	}
	
	}
	public static void main(String[] args) {
		
		try
		{
			String inp="C-small-attempt0";
			System.setIn(C.class.getResourceAsStream(inp+".in"));
			System.setOut(new PrintStream(new File("outputC.out")));
			
		}
		catch(FileNotFoundException e)
		{
			e.printStackTrace();
		}
		
		new C();

	}

}
