package jp.funnything.competition.util;

import java.math.BigInteger;

/**
 * Utility for BigInteger
 */
public class BI {
    public static BigInteger ZERO = BigInteger.ZERO;
    public static BigInteger ONE = BigInteger.ONE;

    public static BigInteger add( final BigInteger x , final BigInteger y ) {
        return x.add( y );
    }

    public static BigInteger add( final BigInteger x , final long y ) {
        return add( x , v( y ) );
    }

    public static BigInteger add( final long x , final BigInteger y ) {
        return add( v( x ) , y );
    }

    public static int cmp( final BigInteger x , final BigInteger y ) {
        return x.compareTo( y );
    }

    public static int cmp( final BigInteger x , final long y ) {
        return cmp( x , v( y ) );
    }

    public static int cmp( final long x , final BigInteger y ) {
        return cmp( v( x ) , y );
    }

    public static BigInteger div( final BigInteger x , final BigInteger y ) {
        return x.divide( y );
    }

    public static BigInteger div( final BigInteger x , final long y ) {
        return div( x , v( y ) );
    }

    public static BigInteger div( final long x , final BigInteger y ) {
        return div( v( x ) , y );
    }

    public static BigInteger mod( final BigInteger x , final BigInteger y ) {
        return x.mod( y );
    }

    public static BigInteger mod( final BigInteger x , final long y ) {
        return mod( x , v( y ) );
    }

    public static BigInteger mod( final long x , final BigInteger y ) {
        return mod( v( x ) , y );
    }

    public static BigInteger mul( final BigInteger x , final BigInteger y ) {
        return x.multiply( y );
    }

    public static BigInteger mul( final BigInteger x , final long y ) {
        return mul( x , v( y ) );
    }

    public static BigInteger mul( final long x , final BigInteger y ) {
        return mul( v( x ) , y );
    }

    public static BigInteger sub( final BigInteger x , final BigInteger y ) {
        return x.subtract( y );
    }

    public static BigInteger sub( final BigInteger x , final long y ) {
        return sub( x , v( y ) );
    }

    public static BigInteger sub( final long x , final BigInteger y ) {
        return sub( v( x ) , y );
    }

    public static BigInteger v( final long value ) {
        return BigInteger.valueOf( value );
    }
}

import java.io.*;
import java.util.*;
import java.math.*;
public class Qual22C
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader ips=new BufferedReader(new FileReader("C-small-attempt0.in"));
		PrintWriter ops=new PrintWriter(new FileWriter("recno.in"));
		int T=Integer.parseInt(ips.readLine());
		for(int i=0;i<T;i++)
		{
			String line=ips.readLine();
			char[] ca=line.toCharArray();
			int count=0,j=0, t=0, A=0, B=0, rnc=0, n=0, m=0, rev=0, temp=0, tryy=0;
			for(j=ca.length-1; ca[j]!=' '; j--)
			{
				t=ca[j]-'0';
				B=B+(int)(Math.pow(10,count)*t);	
				count++;
			}
			j--;
			count=0;
			for(; j>=0; j--)
			{
				t=ca[j]-'0';
				A=A+(int)(Math.pow(10,count)*t);	
				count++;
			}
			//System.out.println("A: "+A+" B: "+B+" nog: "+count);
			n=A;
			int pw=0;
			for(int k=0; k<=(B-A); k++)
			{
				//n++;
				m=n;
				temp=m;
				rev=0;
				pw=0;
				while(temp!=0)
				{
					t=temp%10;
					rev=(rev*10)+t;
					temp=temp/10;
					pw++;
				}
				//System.out.println(rev);
				t=rev%10;
				tryy=(t*(int)(Math.pow(10,(count-1))));
				m=((m-tryy)*10)+t;
				//System.out.println(n+" : "+m);
				while(m!=n)
				{
					if(n<m && m>=A && m<=B)
						rnc++;
					temp=m;
					rev=0;
					pw=0;
					while(temp!=0)
					{
						t=temp%10;
						rev=(rev*10)+t;
						temp=temp/10;
					}
					//System.out.println(rev);
					t=rev%10;
					tryy=(t*(int)(Math.pow(10,(count-1))));
					//System.out.println(t);
					//System.out.println(tryy);
					if((m-tryy)<0)
						m=(m*10);
					else
						m=((m-tryy)*10)+t;
					//System.out.println("1. "+n+" : "+m);
				}
				n++;
			}
			ops.println("Case #"+(i+1)+": "+rnc);	
				
		}
		ips.close();
		ops.close();
	}
}