import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

//	static int MAX = 10000;
	static int MAX = 2000000;
	static Object[] All = new Object[MAX+1];
	
	static int size( int x ) {
		if(x>999999) return 7;
		if(x>99999)  return 6;
		if(x>9999)   return 5;
		if(x>999)    return 4;
		if(x>99)     return 3;
		if(x>9)      return 2;
		return 1;
	}
	static int[] rotate( int value ) {
		List<Integer> result = new ArrayList<Integer>();
		int[] V = new int[8];
		int s = size(value);
		int x = value;
		
		for(int i=s-1;i>=0;i--) {
			V[i] = x%10;
			x /=10;
		}
		int rot;
		for(int i=1; i<s; i++) {
			if(V[i]!=0){
				rot=0;
				for(int j=0,ii=i;j<s; j++,ii=(ii+1)%s){
					rot=rot*10+V[ii];
				}
				if(rot>value && !result.contains(rot))
					result.add(rot);
			}
		}
		if( result.isEmpty() )
			return null;
		int[] r = new int[result.size()];
		for(int i=0; i<r.length; i++)
			r[i]=result.get(i);
		return r;
	}
	
	static void precalculate() {
		for(int i=1; i<=MAX; i++){
			All[i] = rotate(i);
		}
	}
	static int solve( Scanner in ) {
		int A, B, sol=0;
		
		A = in.nextInt();
		B = in.nextInt();

		for( int i=A; i<=B; i++) {
//			List<Integer> result = rotate(i);
			if( All[i]!=null ) {
				for(int value: (int[])All[i] ) {
					if( value <= B )
						sol++;
				}
			}
		}

		return sol;
	}
	
	public static void main ( String args[] ) {
		int T; 
		Scanner in = new Scanner(System.in);
		T = in.nextInt();
		int cnt=0;
		int sol;
		precalculate();
		for( cnt=1; cnt<=T; cnt++ ) {
			sol = solve( in );
			System.out.printf("Case #%d: %d\n", cnt, sol);
		}

	}
}

import java.util.ArrayList;
import java.util.Collection;

/**
 * User: avokin
 * Date: 4/14/12
 */
public class ProblemC {
    private static int[] deg = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};

    private static int recycled(int a, int b, int n) {
        int result = 0;
        int i = 1;
        Collection<Integer> counted = new ArrayList<Integer>();
        while (i < n) {
            int a1 = a / deg[i];
            int a2 = a % deg[i];
            int a3 = a2 * deg[n - i] + a1;
            if (a < a3 && a3 <= b) {
                if (!counted.contains(a3)) {
                    result++;
                }
                counted.add(a3);
            }
            i++;
        }
        return result;
    }

    private static int solve(int a, int b) {
        int result = 0;
        int n = ("" + a).length();
        for (int i = a; i < b; i++) {
            result += recycled(i, b, n);
        }
        return result;
    }

    public static void main(String[] args) {
        String input = "50\n" +
                "1000000 2000000\n" +
                "1003717 1987538\n" +
                "1013804 1939331\n" +
                "1222652 1836943\n" +
                "831085 961576\n" +
                "1323254 1655499\n" +
                "1036764 1919078\n" +
                "54728 86069\n" +
                "1140403 1378888\n" +
                "1086580 1931538\n" +
                "4017 5065\n" +
                "47682 47682\n" +
                "1075058 1974024\n" +
                "1104180 1282545\n" +
                "1081837 1579766\n" +
                "1081844 1913145\n" +
                "1054644 1914812\n" +
                "200978 590182\n" +
                "17 79\n" +
                "401165 866289\n" +
                "1503092 1980132\n" +
                "1001493 1921033\n" +
                "1092675 1901907\n" +
                "1676026 1895467\n" +
                "39677 93416\n" +
                "1127 7446\n" +
                "205 445\n" +
                "1097902 1907197\n" +
                "229602 483412\n" +
                "74999 89942\n" +
                "1078656 1915322\n" +
                "44 52\n" +
                "1049694 1900352\n" +
                "100000 999999\n" +
                "4251 6207\n" +
                "1079496 1901886\n" +
                "191939 567669\n" +
                "1011791 1962213\n" +
                "35390 98715\n" +
                "364 920\n" +
                "100 101\n" +
                "11868 53377\n" +
                "443 748\n" +
                "10000 10000\n" +
                "1091806 1930053\n" +
                "1070990 1934498\n" +
                "1 9\n" +
                "332045 943240\n" +
                "7621 9867\n" +
                "1028742 1028742\n";

        String[] lines = input.split("\n");
        int T = Integer.parseInt(lines[0]);
        for (int i = 1; i <= T; i++) {
            String line = lines[i];
            String[] items = line.split(" ");
            int a = Integer.parseInt(items[0]);
            int b = Integer.parseInt(items[1]);
            int solution = solve(a, b);
            System.out.println("Case #" + i + ": " + solution);
        }

    }
}
