import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.io.*;
import java.util.*;
//import java.math.*;

public class c {

	public static void main(String[] args) throws IOException
	{
		Scanner qwe = new Scanner(new File("c.in"));
		BufferedWriter out = new BufferedWriter(new FileWriter("c.out"));
		int t = qwe.nextInt();
		for(int i = 1; i <= t; i++)
		{
			int a = qwe.nextInt();
			int b = qwe.nextInt();
			int[] been = new int[2000001];
			long count = 0;
			
			for(Integer j =a; j <= b; j++)
			{
				//if(been[j] > 1 && i == 4)
					//System.out.println(i + " " +j +  " " + been[j]);
				if(been[j] > 0)
					count += been[j];
				String s = j.toString();
				ArrayList<String> tocheck = new ArrayList<String>();
				for(int k = 1; k < s.length(); k++)
				{
					String torec = s.substring(k);
					String end = s.substring(0,k);
					String combin = torec+end;
					if(!tocheck.contains(combin) && Integer.parseInt(combin) < 2000001)
						been[Integer.parseInt(combin)] += 1;
					tocheck.add(combin);
				}
				
			}
			
			out.write("Case #" + i + ": " + count +  "\n");
		}
		out.close();
	}
}

