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

package Happy;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays.*;
import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.StringTokenizer;

/**
 *
 * @author ipoqi
 */
public class Happy {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Happy().haha();
    }

    public void haha() {
        BufferedReader in = null;
        BufferedWriter out = null;
        try{
            in = new BufferedReader(new FileReader("C-large.in"));
            out = new BufferedWriter(new FileWriter("LLL.out"));
            int T = Integer.parseInt(in.readLine());
            System.out.println("T="+T);

            //LinkedList<Integer> mm = new LinkedList<Integer>();
            //mm.add(new LinkedList<Integer>());
           //int[][] mm;
           //for(int ii=0;ii<mm.length;ii++){
           //     mm[0][ii] = 1;
           //}


            for(int i=0;i<T;i++){
                String[] line = in.readLine().split(" ");
                int A = Integer.parseInt(line[0]);
                int B = Integer.parseInt(line[1]);
                //System.out.print(" A = "+A+"\n");
                //System.out.print(" B = "+B+"\n");

                int ans = 0;

                
                for(int j=A;j<B;j++){
                    int n=j;
                    if(n>=10){
                        String N = Integer.toString(n);
                        int nlen = N.length();
                        List<Integer> oks = new ArrayList<Integer>();
                        for(int k=0;k<nlen-1;k++){
                            String M = "";
                            for(int kk=1;kk<=nlen;kk++){
                                 M = M + N.charAt((k+kk)%nlen);
                            }
                            int m = Integer.parseInt(M);
                            //System.out.print(" N = "+N+"\n");
                            //System.out.print(" M = "+M+"\n");

                            if(m>n && m<=B) {
                                boolean isNewOne = true;
                                for(int kkk=0;kkk<oks.size();kkk++){
                                    //System.out.print(" KKK = "+oks.get(kkk)+"\n");
                                    if(m==oks.get(kkk)){
                                        isNewOne = false;
                                    }
                                }
                                if(isNewOne){
                                    //System.out.print(" N = "+N+"\n");
                                    //System.out.print(" M = "+M+"\n");
                                    oks.add(m);
                                    ans++;
                                }
                            }
                        }
                    }
                }
                out.write("Case #"+(i+1)+": "+ans+"\n");
                System.out.print("Case #"+(i+1)+": "+ans+"\n");
            }
            in.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            try{
                in.close();
                out.close();
            }catch(Exception e1){
                e1.printStackTrace();
            }
        }
        System.out.print("YES!\n");
    }

}
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.HashSet;

public class Googlerecycle {
	public static void main (String[] args) {
		FileReader fr = null;
		BufferedReader br = null;
		Writer out = null;
		Writer debug = null;
		try {
			fr = new FileReader(args[0]);
			br = new BufferedReader(fr);
			out = new OutputStreamWriter(new FileOutputStream("googlerecycle-result.txt"));
			debug = new OutputStreamWriter(new FileOutputStream("googlerecycle-debug.txt"));
			String numOfLine = br.readLine();
			int line = 0;
			if (numOfLine != null) {
				line = Integer.valueOf(numOfLine);
			} else {
				return;
			}

			String lineData;
			String[] recycleArray;

			for (int i = 1; i <= line; i++) {
				HashMap<String, HashSet<String>> resultMap = new HashMap<String, HashSet<String>>();
				String resultLine = "";
				int recycledCounter = 0;
				lineData = br.readLine();
				recycleArray = lineData.split(" ");

				if (recycleArray[1].length() != 1) {
					int lowerLimit = Integer.valueOf(recycleArray[0]);
					int upperLimit = Integer.valueOf(recycleArray[1]);

					String iterator;

					for (int j = lowerLimit; j <= upperLimit; j++) {
						iterator = String.valueOf(j);
						String doubleLower = iterator + iterator;
						String iteratorCycled;
						int iteratorLength = iterator.length();
						for (int k = 1; k < iteratorLength; k++) {
							iteratorCycled = doubleLower.substring(k, k + iteratorLength);
							if (!iteratorCycled.startsWith("0") && (!iteratorCycled.equals(iterator))) {
								int recycled = Integer.valueOf(iteratorCycled);
								if (recycled <= upperLimit && recycled >= lowerLimit) {
									if (!resultMap.isEmpty()) {
										if (resultMap.containsKey(iteratorCycled)) {
											HashSet<String> resultSet = resultMap.get(iteratorCycled);
											if (resultSet.contains(iterator)) {
												debug.write("already exist pair: " + iterator + ", " + iteratorCycled + "\n");
											} else {
												if (resultMap.containsKey(iterator)){
													HashSet<String> resultSet2 = resultMap.get(iterator);
													if (!resultSet2.contains(iteratorCycled)) {
														recycledCounter++;
														debug.write(iterator + ", "  + iteratorCycled + "\n");
														resultSet2.add(iteratorCycled);
														resultMap.put(iterator, resultSet2);
													} else {
														debug.write("already exist exact pair: " + iterator + ", " + iteratorCycled + "\n");
													}
												}
												else {
													recycledCounter++;
													debug.write(iterator + ", "  + iteratorCycled + "\n");

													HashSet<String> resultSet2 = new HashSet<String>();
													resultSet2.add(iteratorCycled);
													resultMap.put(iterator, resultSet2);
												}
											}
										} else {
											if (resultMap.containsKey(iterator)){

												HashSet<String> resultSet = resultMap.get(iterator);
												if (!resultSet.contains(iteratorCycled)) {
													recycledCounter++;
													debug.write(iterator + ", "  + iteratorCycled + "\n");
													resultSet.add(iteratorCycled);
													resultMap.put(iterator, resultSet);
												} else {
													debug.write("already exist exact pair: " + iterator + ", " + iteratorCycled + "\n");
												}
											} else {
												recycledCounter++;
												debug.write(iterator + ", "  + iteratorCycled + "\n");

												HashSet<String> resultSet = new HashSet<String>();
												resultSet.add(iteratorCycled);
												resultMap.put(iterator, resultSet);
											}
										}
									} else {
										recycledCounter++;
										debug.write(iterator + ", "  + iteratorCycled + "\n");

										HashSet<String> resultSet = new HashSet<String>();
										resultSet.add(iteratorCycled);
										resultMap.put(iterator, resultSet);
									}
								}
							} else {
								debug.write("not valid recycled: " + iterator + ", " + iteratorCycled + "\n");
							}
						}
					}
				}
				debug.write("\n");

				resultLine = "Case #" + i + ": " + recycledCounter;
				out.write(resultLine);
				if (i != line) {
					out.write("\n");
				}
				System.out.println(resultLine);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
				fr.close();
				out.close();
				debug.close();
			} catch(Exception e) {}
		}
	}
}
