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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.*;

/**
 *
 * @author virginia
 *
 */
public class RecycledNumbers {
	public static int countn(int v)
	{
		int count=0;
		while (v> 0 && count<10 )
			{
				   int r = v % 10;
					count++;
				   v = v / 10;
	        }
	        return count;
		}
 public static void main(String[] args) {

 try {
   BufferedReader br = new BufferedReader(new FileReader("C-small-attempt1.in"));
   BufferedWriter output=new BufferedWriter(new FileWriter("Output.txt"));
  PrintWriter pw = new PrintWriter(output);

int n = Integer.parseInt(br.readLine());
 int[][] result = new int[n][2];

 String line;
 int a= 0;
 while ((line = br.readLine()) != null) {
  String[] tokens = line.split("\\s");

  for (int j = 0; j <2; j++) {
   result[a][j] = Integer.parseInt(tokens[j]);
  }

  a++;
 }
    int index = 0;

   for(int i =0; i < n; i++)
   {
	    int found=0;
								index++;
							   int A=result[i][0];
							   int B=result[i][1];
							   for(int j=A;j<=B;j++)
							   {
											  int cnt=0;
											  int num=j;
											  int rev=0;
												while (num> 0 && cnt<10 )
												{
													   int r = num % 10;
														cnt++;
													   num = num / 10;

												}
												int num1=j;
												int num2=j;
												int p=cnt-1;
												int r=0;
												do
												{
													cnt--;
													int s=(num1)%10;
													num2=num2/10;
													num1=(int)(s*Math.pow(10,(p)))+(num2);

													num2=num1;

													if(RecycledNumbers.countn(j)==RecycledNumbers.countn(num1))
													{
													if((A<=j)&&(j<num1)&&(num1<=B))
													{


														 found++;
												}}
												 }while(cnt>0);
								  }
   pw.print("Case #" + index + ": ");
   pw.println(found);
   System.out.print("Case #" + index + ": ");
   System.out.println(found);
   }
   output.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}
