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.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class RecycledNumbers {

	private long low;
	private long high;
	private Map<Long, Boolean> map = new HashMap<Long, Boolean>();
	private int recycycled = 0;

	public static void main(String[] args) throws NumberFormatException,
			IOException {

		File file = new File("C:\\Users\\xebia\\Downloads\\C-small-attempt0.in");

		FileInputStream fis = new FileInputStream(file);
		DataInputStream in = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		int numberOfTestCases = new Integer(br.readLine());
		for (int j = 0; j < numberOfTestCases; j++) {

			RecycledNumbers re = new RecycledNumbers();
			String[] strings = br.readLine().split(" ");
			String s = strings[0];
			String s2 = strings[1];
			long high = new Long(s2);
			long low = new Long(s);
			int numberOfDigits = s.length();
			for (long i = low; i <= high; i++) {
				int roundOffFigure = 1;
				for (int k = 0; k < numberOfDigits - 1; k++) {
					roundOffFigure = roundOffFigure * 10;
					long lastDigit = (long) (i % roundOffFigure);
					String str = "" + lastDigit;

					if (str.length() == k + 1) {

						long startingCombination = (long) (i / roundOffFigure);
						if (lastDigit == 0) {
							continue;
						}
						long number = (long) (lastDigit
								* (Math.pow(10, numberOfDigits - str.length())) + startingCombination);

						if (number >= low && number <= high) {
							if (number != i) {
								Boolean bool = re.map.get(number * i);
								if (bool == null) {
									re.map.put(number * i, true);
									re.recycycled++;
								}

							}
						}
					}
				}

			}
			System.out.println("Case #" + (j + 1) + ": " + re.recycycled);
		}
	}

	public void setLow(long low) {
		this.low = low;
	}

	public long getLow() {
		return low;
	}

	public void setHigh(long high) {
		this.high = high;
	}

	public long getHigh() {
		return high;
	}

	public void setRecycycled(int recycycled) {
		this.recycycled = recycycled;
	}

	public int getRecycycled() {
		return recycycled;
	}

}
