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

/**
 *
 * @author Suarabh Agarwal
 */
import java.io.*;
import java.util.Scanner;

public class Main3
{
 public static void main(String args[])
  {
  try{
  Scanner scan1 = new Scanner(new FileReader("src//codejam///input"));
    //    Scanner  scan1 = new Scanner(new FileReader("input"));
  //Scanner  scan2 = new Scanner(new FileReader("output"));
  //Scanner  scan3 = new Scanner(new FileReader("test.in"));
  PrintWriter out = new PrintWriter("output1.txt");
  String T = scan1.nextLine();
  int test_case = Integer.parseInt(T);
  int count = test_case;
  //int answer = 0;
  while(count>0)
  {
      int A = scan1.nextInt();
      int B = scan1.nextInt();
      int temp[] = new int[3];
      int temp1[] = new int[3];
      int temp2[] = new int[3];
      //System.out.print(a[0]);
      //System.out.print(a[1]);
      //System.out.println(a[2]);
      int answer = 0;
      int count1 = B-A;
      int num = A;
      while(count1>=0)
      {
        // System.out.println(num);

          temp[0]=num/100;
          temp[1]=(num%100)/10;
          temp[2]=(num%100)%10;

           // System.out.print(temp[0]);
           // System.out.print(temp[1]);
           // System.out.println(temp[2]);
          if(temp[0]!=0)
          {
            temp1[0]=temp[2];
            temp1[1]=temp[0];
            temp1[2]=temp[1];
            int num1= temp1[0]*100+temp1[1]*10+temp1[2];
            if(num1>num && num1<=B)
            {
             answer++;
            }
             temp2[1]=temp[2];
             temp2[2]=temp[0];
             temp2[0]=temp[1];
            int num2= temp2[0]*100+temp2[1]*10+temp2[2];
             if(num2>num && num2<=B)
            {
              answer++;
            }
          }
          else if(temp[1]!=0)
          {
            // temp1[0]=temp[2];
            temp1[1]=temp[2];
            temp1[2]=temp[1];
            int num1= temp1[1]*10+temp1[2];
            if(num1>num && num1<=B)
            {
             answer++;
            }
          }
          num++;
          count1--;
      }
      out.println("Case #"+(test_case-count+1)+": "+ answer);
      count--;
  }
  out.close();

  }
  catch(Exception e)
      {
      System.err.println("Error: " + e.getMessage());
      }
  }
  }