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.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	private static final int[][] cache;
	private static final int A = 0, B = 2000000;

	static {
		try {
			File f = new File("cache");
			if (f.exists()) {
				cache = (int[][]) new ObjectInputStream(new FileInputStream(f)).readObject();
			} else {
				cache = new int[B+1][];
				for (int j = 12; j < B; j++) {
					int permutation = String.valueOf(j).length();
					HashMap<Integer, Boolean> hit = new HashMap<Integer, Boolean>();
					for (int z = 1; z < permutation; z++) {
						int div = (int) Math.pow(10, z);
						if (j % div >= div / 10) {
							int newnum = j / div + j % div * (int) Math.pow(10, permutation - z);
							if (newnum >= A && newnum <= B && newnum > j) {
								if (hit.get(newnum) == null) {
									hit.put(newnum, true);
								}
							}
						}
					}
					ArrayList<Integer> l = new ArrayList<Integer>(hit.keySet());
					Collections.sort(l);
					int[] vals = new int[l.size()];
					for (int i = 0; i < l.size(); i++) {
						vals[i] = l.get(i);
					}
					cache[j] = vals;
				}

				new ObjectOutputStream(new FileOutputStream(f)).writeObject(cache);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(new File("input"));
		BufferedWriter w = new BufferedWriter(new FileWriter(new File("output")));
		int cases = s.nextInt();
		for (int i = 0; i < cases; i++) {
			s.nextLine();
			int a = s.nextInt();
			if (a < 12) {
				a = 12;
			}
			int b = s.nextInt();

			int answer = 0;

			for (int j = a; j < b; j++) {
				int[] vals = cache[j];
				for (int val : vals) {
					if (val < 0) {
						continue;
					}
					if (val > b) {
						break;
					}
					answer++;
				}
			}

			w.write("Case #");
			w.write(String.valueOf(i + 1));
			w.write(": ");

			w.write(String.valueOf(answer));

			w.write("\n");
		}
		w.close();
	}

}
