import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int caze, T;
	int A, B;

	void run(){
		T=sc.nextInt();
		for(caze=1; caze<=T; caze++){
			A=sc.nextInt();
			B=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int n=A; n<=B; n++){
			int digit=(int)(log10(n)+EPS);
			int d=(int)pow(10, digit);
			// debug("n", n);
			for(int m=rot(n, d); m!=n; m=rot(m, d)){
				// debug("m", m);
				if(n<m&&m<=B){
					ans++;
				}
			}
		}
		answer(ans+"");
	}

	int rot(int n, int d){
		return n/10+n%10*d;
	}

	void answer(String s){
		println("Case #"+caze+": "+s);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		try{
			System.setIn(new FileInputStream("dat/C-small.in"));
			System.setOut(new PrintStream(new FileOutputStream("dat/C-small.out")));
		}catch(Exception e){}
		new C().run();
		System.out.flush();
		System.out.close();
	}
}


import java.io.*;
import java.util.HashSet;
import java.util.Scanner;

public class Numbers {

    public static void main(String[] args) throws IOException {
        Numbers numbers = new Numbers();
        numbers.findNumbers();
    }

    public void findNumbers() throws IOException {
        Scanner sc = new Scanner(new File("D:/testing/a.txt"));
        BufferedWriter bf = new BufferedWriter(new FileWriter("D:/testing/b.txt", false));
        HashSet<String> hs = new HashSet<String>();

        int T = sc.nextInt();
        for (int i = 1; i <= T; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            hs.clear();
            
            int digits = (int) Math.log10(a);

            for (int n = a; n <= b; n++) {
                for (int j = 1; j <= digits; j++) {
                    int m = swapDigits(n, j);
                    if (n < m && m <= b) {
                        hs.add(String.valueOf(m) + String.valueOf(n));
                    }
                }
            }
            int val=hs.size();
            System.out.println("Case #" + i+": "+val);
            bf.write("Case #" + i+": "+val+ "\n");
        }
        bf.close();
    }

    public int swapDigits(int val, int d) {
        int power=(int)Math.pow(10, d);
        int x = val/power;
        int y = val % power;
        return y * (int) Math.pow(10, (int) Math.log10(x) + 1) + x;
    }
}
