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.Scanner;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class Recycled {
  public static void main(String[] args) {
	try {
	  Scanner sc = new Scanner(new File("input.in"));
	  FileOutputStream output = new FileOutputStream("output.txt");
	  PrintStream p = new PrintStream(output);
	  int cases = Integer.parseInt(sc.nextLine());
	  for ( int i = 0; i < cases; i++ ) {
	    String aCase = sc.nextLine();
		int res = -1;
		int A = 0, B = 0;
		Scanner tmp = new Scanner(aCase);
		if(tmp.hasNextInt())
		  A = tmp.nextInt();
        if(tmp.hasNextInt())
		  B = tmp.nextInt();
		
        if(A >= B)
		  res = 0;		
		else
	      res = findRecycle(A,B);
		  
		int x = i+1;
        p.println("Case #" + x + ": " + res);		
	  }
	}
	catch(Exception e) {
	  e.printStackTrace();
	}
  }
  
   public static int findRecycle(int A, int B) {
     System.out.println("Find recycle " + A +", " + B);
     int count = 0;
	 for (int n = A; n < B; n++) {
	   for (int m = n + 1; m <= B; m++) {
	     if(isRecycled(Integer.toString(n), Integer.toString(m)))
		   count++;
		   //System.out.println(count);
	   }
	 }
	 return count;
   }
   
   public static boolean isRecycled(String n, String m) {
     int suffixes = n.length();
	 for (int i = 1; i < suffixes; i++) {
	   String tmp = n.substring(i);
       String toComp = tmp;
       for (int x = 0; x < i; x++) {
	     toComp += n.charAt(x);
       }	   
	   if(toComp.equals(m))
	     return true;	
	 }
     return false;
   }
  }