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.util.*;

public class RecycledNum
{
  private static int testCase;

  
  public static void main( String[] args )
  {
    Scanner s = new Scanner( System.in );
    RecycledNum r = new RecycledNum();
    r.setTestCase(Integer.parseInt(s.nextLine()));
    for( int i = 0; i < testCase; i++ )
    {
      int A = s.nextInt();
      int B = s.nextInt();
      s.nextLine();
      if( B/A < 10)
      {
        System.out.println( "Case #" +(i+1) +": " + r.recycle( A, B ) );
      }
    }
  }
  public RecycledNum()
  {
    this.testCase = 1;
  }
  public void setTestCase( int T )
  {
    if( T>=1 && T<=50 )
      this.testCase = T;
  }
  public int getTestCase()
  {
    return this.testCase;
  }
  public int recycle(int A, int B)
  {
    int n = 0;
    double j = A;

    int count = 0;
    while( j >= 1)
    {
      j = j/10;
      n = n + 1;
    }
    for( int i = A; i <= B; i++ )
    {
      //System.out.println("original "+ i);
      char[] array = new char[n];
      String numstri = i + "";
      for( int m = 0; m < n; m++)
      {
        array[m]=numstri.charAt(m);
      }
      int[] pair = new int[n];
      for( int q = 0; q< pair.length; q++)
      {
        pair[q] = 0; 
      }
      int count2 = 0;
      for ( int k = 0 ; k < n-1; k++ )
      {
        
        String str = "";
        String rts = "";
        for( int p = 0; p < n - k-1; p++ )
        {
          str = str + array[p];
          ///System.out.println( str );
        }
        for( int p = n-k-1; p < n; p++)
        {
          rts = rts + array[p];
           //System.out.println(rts );
        }
        String stri = rts + str;
        // System.out.println( stri);
        int num = Integer.parseInt(stri);
        boolean check = true;
        if( num <= B && num >= A && num != i )
        {
          
          for( int q = 0; q < pair.length;q++ )
          {
            if(pair[q] == num ){
              check = false;
            }
          }
          if( check )
          {
            count++;
            count2++;
           // System.out.println(count);
            pair[count2-1] = num;
            //System.out.println( num +" ");
          }
          
        }
      }
 
    }
    return count/2;
  }
  
  
}