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

import java.io.*;

class RecycledNumbers
{
  public static void main(String[] args)
  {
    try {
    //parse the input
    FileInputStream fstream = new FileInputStream(args[0]);
    DataInputStream dstream = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(dstream));
    String line = "";

    int numCases = Integer.parseInt(br.readLine());
//System.out.println("num cases: " + numCases);

    for(int lineIdx = 0; lineIdx < numCases; lineIdx++)
    {
      line = br.readLine();
      String[] words = line.split(" ");
      int n = Integer.parseInt(words[0]);
      int m = Integer.parseInt(words[1]);
//System.out.println(n + " " + m);
      int numRecycledNumbers = 0;
      for(int i = n; i <= m; i++)
      {
        for(int j = i+1; j <= m; j++)
          if(countRecycledNumbers(i, j))
            numRecycledNumbers++;
      }
//System.out.println(numRecycledNumbers);
      // write output
      BufferedWriter out = new BufferedWriter(new FileWriter("outfilename", true)); 
      out.write("Case #" + (lineIdx+1) + ": " + numRecycledNumbers + "\n");
      out.close(); 
    }
  }
  catch(FileNotFoundException ex)
  {
    System.out.println(ex);
  }
  catch(IOException ex)
  {
    System.out.println(ex);
  }
  }

  static boolean countRecycledNumbers(int n, int m)
  {
    String nStr = "" + n;
    String mStr = "" + m;
//System.out.println(nStr + " " + mStr);
    if(nStr.length() == mStr.length())
    {
//System.out.println("length condition hit");
      if( (nStr+nStr).indexOf(mStr) >= 0 )
      {
//        System.out.println("index condition hit");
        return true;
//System.out.println(numRecycledNumbers);
      }
    }
    return false;
  }
}


