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.*;
import java.util.*;
import java.math.*;

public class Main implements Runnable {
	
    static int power = 1;

	private static String filename;

	public static void main(String[] args) {
		if (args.length>0 && args[0].equals("f")) filename = "input.txt";
		else filename = "";
		new Thread(new Main()).start();
	}

    private static void debug(Object ... str) {
        for (Object s : str) System.out.print(s + ", ");
        System.out.println();
    }


    private void check(int x, int y, int ndig) {
        int temp = x;
        int[] digx = new int[ndig];
        int[] digy = new int[ndig];
        for (int i = 0; i < ndig; ++i, temp = temp / 10) {
            digx[i] = temp % 10;
        }
        temp = y;
        for (int i = 0; i < ndig; ++i, temp = temp / 10) {
            digy[i] = temp % 10;
        }
        boolean equal = false;   
        for (int sh = 1; !equal && sh < ndig; ++sh) {
            equal = true;
            for (int i = 0; equal && i < ndig; ++i) {
                if (digx[(i + sh) % ndig] != digy[i]) {
                    equal = false;
                }
            }
        }
        if (!equal || x >= y)
            System.out.println("HAHAHA " + x + " " + y);
    }

	public void run() {
		try{
            MyScanner in;
			Locale.setDefault(Locale.US);
			if (filename.length()>0) in = new MyScanner(filename);
			else in = new MyScanner(System.in);
			PrintWriter out = new PrintWriter(System.out);
            int T = in.nextInt();
            for (int test = 0; test < T; ++test) {
                int a = in.nextInt();
                int b = in.nextInt();
                int temp = a;
                int ndig = 0;
                while (temp > 0) {
                    temp /= 10;
                    ndig++;
                }

                int[] dig = new int[ndig];

                power = 1;
                for (int i = 1; i<ndig; ++i) 
                    power *= 10;

                int ans = 0;

                boolean[] was = new boolean[2000001];
                int[] stack = new int[ndig];

                for (int x = a; x <= b; ++x) {
                    temp = x;
                    for (int c = 0; c < ndig; ++c, temp = temp / 10) {
                        dig[c] = temp % 10;
                        if (dig[c] == 0)
                            continue;
                    }

                    int stack_size = 0;
                    int y = x / 10 + dig[0] * power;
                    for (int c = 1; c < ndig; ++c) {
                        if ((x < y && y <= b) && !was[y]) {
                            ans++;
                            stack[stack_size++] = y;
                            was[y] = true;
                            //check(x, y, ndig);
                        }
                        y = y / 10 + dig[c] * power;
                    }

                    for (int i = 0; i < stack_size; ++i) {
                        was[stack[i]] = false;
                        stack[i] = 0;
                    }

                }
                out.println("Case #" + (1 + test) + ": " + ans);
            }
            out.close();
            in.close();
			                                              
		}catch(Exception e) {
			e.printStackTrace();
		}
	}

}

class MyScanner {
	BufferedReader in;
	StringTokenizer st;

	MyScanner(String file){
	        try{
		in = new BufferedReader(new FileReader(new File(file)));
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	MyScanner(InputStream inp){
		try{                                   
                	in = new BufferedReader(new InputStreamReader(inp));
		}catch (Exception e){
			e.printStackTrace();
		}
	}

    void skipLine(){
        st = null;
    }

	boolean hasMoreTokens(){
		String s = null;
		try{
			while ((st==null || !st.hasMoreTokens())&& (s=in.readLine()) != null) st = new StringTokenizer(s);
			if ((st==null || !st.hasMoreTokens())&& s==null) return false;
	        }catch(IOException e){
	        	e.printStackTrace();
	        }
		return true;
	}

	String nextToken(){
		if (hasMoreTokens()){
			return st.nextToken();
		}
		return null;
	}

	int nextInt(){
		return Integer.parseInt(nextToken());
	}

	long nextLong(){
		return Long.parseLong(nextToken());
	}

	double nextDouble(){
		return Double.parseDouble(nextToken());
	}


	String nextString(){
		return nextToken();
	}
	void close(){
		try{
			in.close();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

}





