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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.util.Scanner;
import java.io.*;
public class Tobi
{
    static String out="",output="";

    public static void main(String[] args)
    {
        try
        {
             Scanner in = new Scanner(new File("file.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;
        
        
        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;
    }
}
