import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}


import java.io.*;
import java.util.*;

public class QualC{		
		
		private BufferedReader in;	
		private StringTokenizer st;
		private PrintWriter out;
		
		void solve() throws IOException{
			
			int kases = nextInt();
			int kase = 0;
			while(kases-->0){
				kase++;
				out.print("Case #"+kase+": ");
				int a = nextInt();
				int b = nextInt();
				int ans = 0;
				for (int n = a; n <= b; n++) {
					for (int m = n+1; m <= b; m++) {
						String x = n+"";
						String y = m+"";
						if(x.length() != y.length()) continue;
						String z = x+x;
						if(z.contains(y)) ans++;
					}
				}
				out.println(ans);
				
			}
		}
			

		QualC() throws IOException {
			in = new BufferedReader(new FileReader("input.txt"));	
			out = new PrintWriter(new FileWriter("output.txt"));
			eat("");
			solve();	
			out.close();
		}

		private void eat(String str) {
			st = new StringTokenizer(str);
		}

		String next() throws IOException {
			while (!st.hasMoreTokens()) {
				String line = in.readLine();
				if (line == null) {
					return null;
				}
				eat(line);
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public static void main(String[] args) throws IOException {
			new QualC();
		}

		int gcd(int a,int b){
			if(b>a) return gcd(b,a);
			if(b==0) return a;
			return gcd(b,a%b);
		}

}
