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.File;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class CodejamC {

	public static final String TEST = "test.in", SMALL = "C-small-attempt0.in", LARGE = "C-large.in";
	public static final String OUTPUT = "out.txt";
	
	static int count = 0;
	
	public static void main(String[] args) throws Exception
	{
		
		solve(SMALL);
	}

	public static void solve(String filename) throws Exception
	{
		Scanner in = new Scanner(new File(filename));
		
		int cases = in.nextInt();
		in.nextLine();
		
		PrintWriter out = new PrintWriter(new File(OUTPUT));
		
		for(int num = 1; num <= cases; num++)
		{
			int a = in.nextInt();
			int b = in.nextInt();
			count = 0;
			in.nextLine();
			int result = 0;
			Set<Pair> perms = new HashSet<Pair>();
			for(int i = a; i <= b; i++)
			{
				String str = String.valueOf(i);
				for(int j = 0; j < str.length(); j++)
				{
					String newStr = str.substring(str.length() - j, str.length()) + str.substring(0, str.length() - j);
					int val = Integer.parseInt(newStr);
					if(val >= a && val <= b && !newStr.equals(str) && newStr.charAt(0)!='0')
					{
						perms.add(new Pair(str, newStr));
					}
				}
				//perms.remove(str);
			}
			result = perms.size();
			out.println("Case #"+num+": "+result);
			System.out.println("Case #"+num+": "+result);
		}
		
		out.close();
	}
}

class Pair
{
	String n, m;
	
	public Pair(String str, String newStr) {
		n = str;
		m = newStr;
	}

	@Override
	public boolean equals(Object o)
	{
		Pair other = (Pair) o;
		return (n.equals(other.n)&& m.equals(other.m)) || (m.equals(other.n) && n.equals(other.m));
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return n.hashCode() + m.hashCode();
	}
	
	
}
