import java.io.*;
import java.util.*;

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

import java.util.Scanner;
import java.io.*;
public class Tolu
{
    static String out="",output="";
    
    public static void main(String[] args) 
    {
        try
        {
             Scanner in = new Scanner(new File("input.in")); 
             int n = in.nextInt();                                               
             int count = 1;
             String out = "";
             while(in.hasNext())
             {              
               int a = in.nextInt();
               int b = in.nextInt();
               out += "Case #"+count+": "+ activity(a,b)+"\n";
               count++;
             try
             {
                 File file = new File("output.dat");
                 PrintWriter output = new PrintWriter(file);
                 output.write(out);
                 output.close();
                }
                catch(Exception exception)
                {
                 System.out.println("ERROR");
                }             
             }
    }catch(Exception exception){
        System.out.println("ERROR");
    }
    System.out.println("DONE");       
    }
    
    public static int activity(int A, int B)
    {
        int counter = 0;
        
        //String all[] = myGenerator(Integer.toString(A));  
        for(int i = A; i <= B; i++)
        { 
            String all[] = myGenerator(Integer.toString(i));
            for(int j = 0; j < all.length; j++)
            {
              if((i < Integer.parseInt(all[j])) && (Integer.parseInt(all[j]) <= B))
              {
                counter++;
              }
            }
        }
        return counter;
    }
            
    public static String[] myGenerator(String word)
    {
        String[] all = new String[word.length()-1];//changed frm len - 1
        for(int i = 0; i < all.length; i++)
        {
            all[i] = generate(word);
            word = generate(word);
        }
        return all;
    }
    public static String generate(String w)
    {
        String ans = w.substring(w.length()-1);
        for(int i = 0; i < w.length()-1; i++)  
        {
          ans += w.substring(i,i+1);
        }
        return ans;
    }
}
