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.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class B {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        try (FileReader file = new FileReader("entrada.in"); Scanner scanner = new Scanner(file)) {
            int T,A,B,i,j,k=0,total=0; 
            String xs;
            T=scanner.nextInt();
            boolean matriz[][] = new boolean[1000][];
            for (i=0;i<1000;i++)
                matriz[i] = new boolean[1000];
            System.setOut(new PrintStream("salida.out"));
            for (i=1;i<=T;i++){
                for (j=0;j<1000;j++)
                    Arrays.fill(matriz[j], false);
                A=scanner.nextInt();
                B=scanner.nextInt();
                for (j=A;j<=B;j++){
                     xs=Integer.toString(j);
                     if (xs.length()==2 && xs.charAt(1)!='0'){
                         k=Integer.parseInt(xs.charAt(1)+""+xs.charAt(0));
                         if (j!=k && k<=B && k>=A)
                            matriz[j][k]=true;
                     }
                     if (xs.length()==3 && xs.charAt(2)!='0'){
                         k=Integer.parseInt(xs.charAt(2)+""+xs.charAt(0)+""+xs.charAt(1));
                         if (j!=k && k<=B && k>=A)
                            matriz[j][k]=true;
                     }
                     if (xs.length()==3 && xs.charAt(1)!='0'){
                         k=Integer.parseInt(xs.charAt(1)+""+xs.charAt(2)+""+xs.charAt(0));
                         if (j!=k && k<=B && k>=A)
                            matriz[j][k]=true;
                     }
                }
                total=conteomatriz(matriz);
                System.out.println("Case #"+i+": "+total);
            }
        }
        
    }
    public static int conteomatriz(boolean[][] m){
        int total=0,i,j;
        for (i=0;i<1000;i++){
            for (j=0;j<1000;j++){
                if (m[i][j]){
                    m[j][i]=false;
                    //System.out.println(i+" "+j);
                    total++;
                }
            }
        }
        return total;
    }
    
}
