import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumber;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.swing.JFileChooser;

/**
 *
 * @author pos
 */
public class RecycledNumbers {

    static Numbers[] TestCases;

    public static void main(String args[]) {
        readFile();
        for (int i = 0; i < TestCases.length; i++) {
            TestCases[i].Calculate();
        }
        WriteToFile();
    }

    private static void readFile() {
        try {
            JFileChooser FC = new JFileChooser();
            String Path = null;
            if (FC.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                Path = FC.getSelectedFile().getPath();

                StringBuffer Text = new StringBuffer();
                FileInputStream FIS = null;
                DataInputStream DIS;
                BufferedReader BR;

                FIS = new FileInputStream(Path);
                DIS = new DataInputStream(FIS);
                BR = new BufferedReader(new InputStreamReader(DIS));
                int TestCasesCount = Integer.valueOf(BR.readLine());

                TestCases = new Numbers[TestCasesCount];
                for (int i = 0; i < TestCasesCount; i++) {
                    String[] AB = BR.readLine().split(" ");
                    TestCases[i] = new Numbers(Integer.valueOf(AB[0]), Integer.valueOf(AB[1]));
                }
                FIS.close();
                DIS.close();
                BR.close();

            }
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
    }

    private static void WriteToFile() {
        FileOutputStream FOS = null;
        DataOutputStream DOS;
        BufferedWriter BW;
        try {
            FOS = new FileOutputStream(new File("Recycled"));
        } catch (FileNotFoundException ex) {
        }
        DOS = new DataOutputStream(FOS);
        BW = new BufferedWriter(new OutputStreamWriter(DOS));

        for (int i = 0; i < TestCases.length; i++) {
            String Line = "Case #" + (i + 1) + ": " + TestCases[i].Result+"\n";
            try {
                BW.write(Line);
            } catch (IOException ex) {
                System.err.println(ex.getMessage());
            }
        }
        try {
            BW.close();
        } catch (IOException ex) {
            System.err.println(ex.getMessage());
        }

    }
}
