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.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.TreeSet;


class Pair implements Comparable<Pair>{
    int a , b;

    public Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pair other = (Pair) obj;
        if (this.a != other.a) {
            return false;
        }
        if (this.b != other.b) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = a*3;
        return hash;
    }

    public int compareTo(Pair o) {
        if ( o.a != this.a ){
            return this.a - o.a;
        }else{
            return this.b - o.b;
        }
    }


}

/**
 *
 * @author Saul Hidalgo
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            Scanner sc = new Scanner(new File("test.txt"));
            PrintStream ps = new PrintStream(new File("output.txt"));

            int T = sc.nextInt();
            for ( int t = 1 ; t <= T ; t++ ){
                int n = sc.nextInt() , m = sc.nextInt();
                int ans = 0;
                TreeSet<Pair> tree = new TreeSet<Pair>();

                for ( int i = n ; i <= m ; i++ ){
                    String num = i + "";
                    for ( int j = 1 ; j < num.length() ; j++ ){
                        String conv = num.substring(j) + num.substring(0, j);
                        int tt = Integer.parseInt(conv);
                        Pair p = new Pair(i, tt);
                        if ( tt > i && tt <= m && !tree.contains(p)){
                            ++ans;
                            tree.add(p);
                        }
                    }
                }
                ps.println("Case #" + t + ": " + ans);
            }

        }
        catch (FileNotFoundException ex) {
            // =(
        }
    }
}
