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.io.*;
public class Palindrome
 {
     public static void main(String args[]) throws IOException
     {
         int N;
         int a,b,i;
         String s[];
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         N=Integer.parseInt(br.readLine());
         for(i=1;i<=N;i++)
         {
             s=br.readLine().split(" ");
             a=Integer.parseInt(s[0]);
             b=Integer.parseInt(s[1]);
             System.out.println("Case #"+i+": "+calc(a,b));
            }
        }
        
     public static int calc(int a,int b)
     {
         int i,j,k,p1,p2,cnt=0;
         int tmp[];
         p1=-1;
         p2=-1;
         for(i=a;i<b;i++)
         {            
            tmp=permute(i);
            for(k=0;k<tmp.length;k++)
            {
                j=tmp[k];
                //
                if(i<j&&j<=b)
                {
                    if(p1==i&&p2==j)
                    {
                    }
                    else
                    {
                        p1=i;p2=j;
                     //System.out.println(i+" "+j);
                     cnt++;
                    }
                }
            }
        }
         return cnt;
       }
       
       public static int[] permute(int tmp)
       {
           int digits=0;
           int cnt,k,i;
           int vals[];
           k=tmp;
           
           String s="";          
           while(k!=0)
           {
               s=(k%10)+s;
               k=k/10;
               digits++;
            }
            cnt=0;
            vals=new int[digits];
           for(i=digits-1;i>=0;i--)
           {
               vals[cnt++]=Integer.parseInt(s.substring(i,digits)+s.substring(0,i));
            }
            return vals;
        }
    }
        
      