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;

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

    int A;
    int B;
    int n;
    int m;
    int Result;

    public Numbers(int A, int B) {
        this.A = A;
        this.B = B;
        this.n = A;
        this.m = n + 1;
    }
    
    String sn;
    String sm;
    int nLength;
    int mLength;
    int nIndex;
    int mIndex;

    private boolean isValid(int n, int m) {
        int[] numberN = new int[10];
        int[] numberM = new int[10];

        sn = n + "";
        sm = m + "";
        nLength = sn.length();
        mLength = sm.length();

        for (int i = 0; i < nLength; i++) {
            nIndex = Integer.valueOf(sn.charAt(i)) - 48;
            numberN[nIndex]++;
            mIndex = Integer.valueOf(sm.charAt(i)) - 48;
            numberM[mIndex]++;
        }
        for (int i = 0; i < 10; i++) {
            if (numberN[i] != numberM[i]) {
                return false;
            }
        }
        //System.out.println(A + "<=" + n + "<" + m + "<=" + B);
        return true;
    }

    public void Calculate() {
        int n, m;
        for (int i = this.A; i < this.B; i++) {
            for (int j = i+1; j <= this.B; j++) {
                n = i;
                m = j;
                if (isValid(n, m))
                    isRecycled(n, m);
            }
        }
    }
    
    private boolean isRecycled(int n, int m){
        String sn=n+"";
        nLength=sn.length();
        for(int i=1;i<nLength;i++){
            if (Integer.valueOf(sn.substring(i)+sn.substring(0, i))==m){
                Result++;
                return true;
            }
        }
        return false;
    }
}
