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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author UDDAMA
 */
public class recyclePair {

    private ArrayList<String> numholder = new ArrayList<String>();

    public void numrecylce(String chars) {
        for (int i = 0; i < chars.length() - 1; i++) {
            this.numholder.add(chars.substring(i + 1) + chars.substring(0, i + 1));
        }
    }

    public void cleanArray() {

        for (int i = 0; i < numholder.size(); i++) {
            String temp = numholder.get(i);
            for (int j = i + 1; j < numholder.size(); j++) {
                if (temp.equalsIgnoreCase(numholder.get(j))) {
                    numholder.remove(j);
                }
            }
        }
    }

    public int recycleCount(String A, String B) {

        int count = 0;
        for (int i = Integer.parseInt(A); i < Integer.parseInt(B); i++) {
            this.numholder.clear();
            this.numrecylce(String.valueOf(i));
            this.cleanArray();

            for (int j = 0; j < numholder.size(); j++) {

                if (Integer.parseInt(numholder.get(j)) > i && Integer.parseInt(numholder.get(j)) <= Integer.parseInt(B)) {
                    count++;
                }
            }
        }
        return count;
    }

    public static void main(String[] args) throws IOException {

        BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
        String inputLine = is.readLine();
        recyclePair rp = new recyclePair();

        int cases = Integer.parseInt(inputLine);

        for (int i = 0; i < cases; i++) {

            inputLine = is.readLine();
            String[] AB = inputLine.split(" ");

            System.out.println("Case #" + (i + 1) + ": " + rp.recycleCount(AB[0], AB[1]));


        }
    }
}