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

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}

import java.util.*;

public class probC
{
	public static int N=2000001, K=0 ;
	
	public static void main (String[] args)
	{
		Scanner scan = new Scanner (System.in) ;
		
		int A[] = new int[N];
		boolean visited[] = new boolean [N];
		
		for (int i=0 ; i<A.length ; i++)
			A[i]=-1;
		
		for (int i=0 ; i<A.length ; i++)
			if (!visited[i])
				rotate(i,A,visited);
		
		int T = scan.nextInt();
		int n1, n2;
		
		for (int t=0 ; t<T ; t++)
		{
			n1 = scan.nextInt();
			n2 = scan.nextInt();
			System.out.printf("Case #%d: %d\n",(t+1),solve(n1,n2,A));
		}
	}
	public static long solve (int n1, int n2, int[] A)
	{
		int[] f = new int[K];
		long cumul[] = new long[N];
		
		int k=0 ;
		
		for (int i=n1 ; i<=n2 ; i++)
		{
			k=A[i];
			if (k!=-1)
			{
				f[k]++;
				cumul[i]=f[k]-1;
			}
			if (i!=0)
				cumul[i]+=cumul[i-1];
		}
		return cumul[n2]-cumul[n1];
	}
	
	public static int choose2 (int n)
	{
		return ((n*(n-1))/2);
	}
	public static void rotate (int n, int[] A, boolean[] visited)
	{
		visited[n]=true;
		String initial = Integer.toString(n);
		String rotated ;
		int newNum=0;
		boolean found=false;
		HashSet<Integer> set = new HashSet ();
		set.add(n); 
		
		for (int off=0  ; off<initial.length() ; off++)
		{
			rotated="";
			for (int i=0 ; i<initial.length() ; i++)
				rotated+=initial.charAt((i+off)%initial.length());
			
			newNum=Integer.valueOf(rotated);
			
			if (!set.contains(newNum) && newNum<A.length && Integer.toString(newNum).length()==initial.length())
			{
				set.add(newNum);
				found=true;
				visited[newNum]=true;
				A[newNum]=K;
				//System.out.println(n+" "+newNum);
			}
		}
		if (found)
		{
			A[n]=K;
			K++;
		}
	}
}
