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;
	}
}

/*
 * Copyright 2012 Bill Bejeck
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package comp;

import java.io.*;

/**
 * User: Bill Bejeck
 * Date: 4/13/12
 * Time: 9:36 PM
 */
public class Recycled {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
        PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(args[1]))));
        int numCases = Integer.parseInt(reader.readLine());
        for (int i = 0; i < numCases; i++) {
            String[] pair = reader.readLine().split(" ");
            int numberOne = Integer.parseInt(pair[0]);
            int numberTwo = Integer.parseInt(pair[1]);
            int count = getRecycled(numberOne, numberTwo);
            String result = String.format("Case #%d: %d", (i + 1), count);
            System.out.println(result);
            writer.println(result);
        }
        writer.flush();
        writer.close();
        reader.close();


    }

    private static int getRecycled(int n, int max) {
        int recycleCount = 0;
        for (int i = 0; i < max; i++) {
            String nSt = Integer.toString(n);
            int newMax = (n + 1);
            for (int k = 0; k < max && newMax <= max; k++) {
                String maxString = Integer.toString(newMax);
                for (int j = nSt.length() - 1; j >= 0; j--) {
                    String end = nSt.substring(j);
                    String start = nSt.substring(0, nSt.indexOf(end, j));
                    if (maxString.startsWith(end) && maxString.endsWith(start)) {
                        if (maxString.equals(end + start)) {
                            recycleCount++;
                        }
                    }

                }
                newMax++;
            }
            n++;
        }
        return recycleCount;
    }
}
