import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * Created with IntelliJ IDEA.
 * User: akim
 * Date: 4/14/12
 * Time: 7:45 PM
 * To change this template use File | Settings | File Templates.
 */
public class C {

    String makeHash(int a) {
        String t = Integer.toString(a);
        String ans = t;
        for (int i = 0; i < t.length(); ++i) {
            t = t.substring(1)+t.charAt(0);
            if (ans.compareTo(t) > 0) ans = t;
        }
//        System.out.println(a + " - " + ans);
        return ans;
    }

    void solve() throws FileNotFoundException {
        PrintWriter out = new PrintWriter(new FileOutputStream("output.txt"));
        Scanner in = new Scanner(new FileInputStream("input.txt"));
        int t = Integer.parseInt(in.nextLine());
        System.err.println(t);
        TreeMap<String, Long> ans = new TreeMap<String, Long>();
        for (int i = 0; i < t; ++i) {
            ans.clear();
            int A = in.nextInt();
            int B = in.nextInt();
            for (int qqq = A; qqq <= B; ++qqq) {
                String hash = makeHash(qqq);
                if (!ans.containsKey(hash)) ans.put(hash, 0L);
                long tmp = ans.get(hash);
                ans.put(hash, tmp + 1);
            }
            long rrr = 0;
            /*for (int a = A; a <= B; ++a)
                for (int b = a + 1; b <= B; ++b)
                    if (makeHash(a).equals(makeHash(b))) --rrr;*/
            for (String h : ans.keySet()) {
                long tmp = ans.get(h);
                rrr += tmp * (tmp - 1) / 2;
            }
            out.println("Case #" + (i + 1) + ": " + rrr);
            System.err.println((i + 1) + " " + rrr);
        }
        out.flush();
        out.close();
    }


    public static void main(String[] args) throws FileNotFoundException {
        new C().solve();
    }
}
