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.util.*;
import java.io.*;
class RecycledNumbers{
static int A,B,l,count=0;
static int v[]=new int[10000];
public static void main(String[] args){
  try {
File file = new File("C-small-attempt1.in");  
 FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr); 
File file1 = new File("Coutput2.in");
FileWriter fw = new FileWriter(file1); 
PrintWriter pw = new PrintWriter(fw);
int T= Integer.valueOf(br.readLine());

int i,p=1,j,k;

while(p<=T)
{	

String G=br.readLine(); 
j=0;i=0;k=1;
int m=1;
String r="";
if(G==null)break;

int l;
for(l=0;l<G.length();l++)
{
r="";
for(;G.charAt(i)!=' ' && i+1<G.length();i++)
{
r+=G.charAt(i);
if(G.charAt(i+1)==' '){j++;}
}
i++;
if(i==G.length())
{j++;r+=G.charAt(i-1);}
	if(j==1)
	A=Integer.valueOf(r);
	else if(j==2)
	B=Integer.valueOf(r);
	

if(i==G.length())
{break;}
}
	 l=length(A);
	count=0;

for(int n=A;n<B;n++)
{
int t=n;
m=n;
	for(j=1;j<=l;j++)
	{
	if(m%10==0)
	{m=shifttwo(m);j++;}
	else
	m=shiftone(m);

	if(t<m && range(m))
	{			
	//System.out.println(t+" "+m);
	count++;
	}

	}
}	

 pw.println("Case #"+p+":  "+count);
	p++;
	}

 fr.close(); 
fw.close();

  } catch(IOException e) { }
}//main


static int length(int a)
{
int c=0;
	while(a>0)
	{
	c++;
	a=a/10;
	}
return c;
}
static int shiftone(int n)
{

	int v=n%10;
	n=n/10;
	return (n+v*pow(10,length(n)));
}
static int shifttwo(int n)
{

	int v=n%100;
	n=n/100;
	return (n+v*pow(10,length(n)));
}
static int pow(int i,int j)
{
	if(j==0)
	return 1;
	return i*pow(i,j-1);
}

static boolean range(int m)
{
	for(int i=A;i<=B;i++)	{
	if(m==i){
			return true;
			}
				}
	return false;
}
}//class
