package jp.funnything.competition.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

import org.apache.commons.io.IOUtils;

public class QuestionReader {
    private final BufferedReader _reader;

    public QuestionReader( final File input ) {
        try {
            _reader = new BufferedReader( new FileReader( input ) );
        } catch ( final FileNotFoundException e ) {
            throw new RuntimeException( e );
        }
    }

    public void close() {
        IOUtils.closeQuietly( _reader );
    }

    public String read() {
        try {
            return _reader.readLine();
        } catch ( final IOException e ) {
            throw new RuntimeException( e );
        }
    }

    public BigDecimal[] readBigDecimals() {
        return readBigDecimals( " " );
    }

    public BigDecimal[] readBigDecimals( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigDecimal[] values = new BigDecimal[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigDecimal( tokens[ index ] );
        }

        return values;
    }

    public BigInteger[] readBigInts() {
        return readBigInts( " " );
    }

    public BigInteger[] readBigInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigInteger[] values = new BigInteger[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigInteger( tokens[ index ] );
        }

        return values;
    }

    public int readInt() {
        final int[] values = readInts();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public int[] readInts() {
        return readInts( " " );
    }

    public int[] readInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final int[] values = new int[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Integer.parseInt( tokens[ index ] );
        }

        return values;
    }

    public long readLong() {
        final long[] values = readLongs();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public long[] readLongs() {
        return readLongs( " " );
    }

    public long[] readLongs( final String separator ) {
        final String[] tokens = readTokens( separator );

        final long[] values = new long[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Long.parseLong( tokens[ index ] );
        }

        return values;
    }

    public String[] readTokens() {
        return readTokens( " " );
    }

    public String[] readTokens( final String separator ) {
        return read().split( separator );
    }
}

import java.io.*;
import java.util.*;
class C3
{
    public static void main(String args[])throws IOException
    {
        FileReader fi = new FileReader("C-small-attempt3.in");
        Scanner in = new Scanner(fi);
        FileWriter fr = new FileWriter("C3-output.out");
        BufferedWriter bw = new BufferedWriter(fr);
        PrintWriter pw = new PrintWriter(bw);
        int T = in.nextInt();
        int ab[][] = new int[T][2];
        for(int i=0;i<T;i++)
        {
            ab[i][0] = in.nextInt();
            ab[i][1] = in.nextInt();
        }
        in.close();
        fi.close();
        for(int i=0;i<T;i++)
        {
            int A = ab[i][0];
            int B = ab[i][1];
            int c=0;
            for(int j=A;j<=B;j++)
            {
                int n = j;
                for(int k=n+1;k<=B;k++)
                {
                    int m = k;
                    if(recycle(n,m))
                    c++;
                }
            }
            pw.println("Case #"+(i+1)+": "+c);
        }
        pw.close();
        bw.close();
        fr.close();
    }
    static boolean recycle(int n,int m)
    {
        int tn =n;
        int c=0;
        while(tn>0)
        {
            tn= tn/10;
            c++;
        }
        tn=n;
        int tn2 = n;
        boolean flag = false;
        while(tn>0)
        {
            int d = tn%10;
            tn = tn/10;
            int tp = (int)Math.pow(10,c-1);
            tn2 = tn2/10;
            tn2 = tp*d+tn2;
            if(tn2==m)
            {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
