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);
		}

	}
}

package gcj;

import java.io.BufferedReader;
import java.io.FileReader;

public class Gcj {
	private static final String path = "/home/me/dev/gcj/";
	private BufferedReader br = null;
	private String[] tokens;
	private int itoken,ntokens;
	
	static public void err(String e) {
		System.out.println("\n**\n"+e+" :-)\n");
		System.exit(1);
	}
	
	public Gcj(String filename) {
		try {
			br = new BufferedReader(new FileReader(path + filename));
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String rawLine() {
		String line = null;
		
		try {
			line = br.readLine();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return line;
	}
	
	
	public String[] readLine() {
		
		String line = rawLine();
		
		if (line == null) {
			tokens = null;
			ntokens = 0;
		}
		else {
			tokens = line.trim().split("\\s+");
			ntokens = tokens.length;
		}
		itoken = 0;
		
		return tokens;
	}
	
	private String nextToken() {
		String err = null;
		if (ntokens < 1) err = "There is no token";
		else if (itoken >= ntokens) err = "No more token";
		else {
			return tokens[itoken++];
		}
		
		Gcj.err(err);
		return null;
	}
	
	public String sToken() {
		return nextToken();
	}

	public String[] sBunch() {
		String[] l = new String[ntokens-itoken];
		int i=0;
		while (itoken < ntokens) l[i++] = tokens[itoken++];
		return l;
	}

	public char cToken() {
		return nextToken().charAt(0);
	}

	public char[] cBunch() {
		char[] l = new char[ntokens-itoken];
		int i = 0;
		while (itoken < ntokens) l[i++] = tokens[itoken++].charAt(0);
		return l;
	}

	public int iToken() {
		return Integer.parseInt(nextToken());
	}

	public int[] iBunch() {
		int[] l = new int[ntokens-itoken];
		int i = 0;
		while (itoken < ntokens) l[i++] = Integer.parseInt(tokens[itoken++]);
		return l;
	}
	
	public long lToken() {
		return Long.parseLong(nextToken());
	}

	public long[] lBunch() {
		long[] l = new long[ntokens-itoken];
		int i = 0;
		while (itoken < ntokens) l[i++]  = Long.parseLong(tokens[itoken++]);
		return l;
	}
	
	public double dToken() {
		return Double.parseDouble(nextToken());
	}

	public double[] dBunch() {
		double[] l = new double[ntokens-itoken];
		int i = 0;
		while (itoken < ntokens) l[i++] = Double.parseDouble(tokens[itoken++]);
		return l;
	}

	
	// -- utils
	
	// keep leading zeroes...
	public int[] breakdownNumber(String s) {
		int n = (s == null ? 0 : s.length());
		int[] aa = new int[n];
		if (n > 0) {
			char[] cc = s.toCharArray();
			for (int i=0 ; i<n ; i++) {
				aa[i] = cc[i] - '0';
			}
		}
		return aa;
	}
	
	
	// --
	
	public void terminate() {
		try {
			if (br != null) br.close();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("");
	}
	
	
	// --- OUTPUT ---
	
	public static void outcase(int n, boolean rc) {
		System.out.print("Case #" + n + ": ");
		if (rc) System.out.print("\n");
	}
	
}
