/*
 * 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.io.*;
import java.util.*;

public class QualiC_Naive
{
  static void sop(String str)
  {
    System.out.println(str);
  }
  
  static void sop1(String str)
  {
    System.out.print(str);
  }
  
  public static void main(String args[])
  {
    long tstart = System.currentTimeMillis();
    if(args.length < 1)
    {
      System.out.println("You have not given input file!");
      System.exit(0);
    }
    File f1 = null;
    Scanner sc = null;
    try
    {
      f1 = new File(args[0]);
      sc = new Scanner(f1);
    }
    catch(Exception e)
    {
      System.out.println("Error opening the input file " + e);
    }
    /*
      int nCases, i, j, k, m, n;
      sc.next();
      sc.nextInt();
      sc.nextLine();
      sc.nextDouble();
    */
    int nCases, i, j, k, m, n;
    nCases = sc.nextInt();
    // sc.nextLine();
    for(i=1; i<=nCases; ++i)
    {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int ans = 0;
      String strn = "" + a;
      // String strm = "" + b;
      int len = strn.length();
      int mult=0;
      switch(len)
      {
        case 2: mult = 10; break;
        case 3: mult = 100; break;
        case 4: mult = 1000; break;
        case 5: mult = 10000; break;
        case 6: mult = 100000; break;
        case 7: mult = 1000000; break;
      }
      if(len == 1)
        ans = 0;
      else
      { 
      /*
        try
	{
	  FileWriter tempf = new FileWriter("temp.dat");
	  BufferedWriter buff = new BufferedWriter(tempf);
	  buff.write("Case " + i + ":-------------------------------------------\n");
      */
        int c[] = new int[len];
        for(j=a; j<=b; j++)
	{ 
	  c[0] = j;
	  HashSet<Integer> x = new HashSet<Integer>();
	  for(k=1; k<len; k++)
	  {
	    c[k] = (c[k-1] % 10) * mult + c[k-1] / 10;
            if(j<c[k] && c[k]<=b)
	      {
	        if(x.add(c[k]))
	          ans++;
	   //   buff.write("" + j + " - " + c2 + "\n");
	      }
	  }

	}
	/*
	  buff.close();
	}
	catch(IOException e1)
	{
	  sop("Error: " + e1);
	}
	*/
      }
  
      sop("Case #" + i + ": " + ans);
    }
    long tend = System.currentTimeMillis();
    System.err.println("Time taken: " + (tend - tstart)/1000.0 + " seconds");
  } // end of main()
}

