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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

public class ProblemC {

	public static void main(String[] args) throws FileNotFoundException {
		start();
	}

	public static void start() throws FileNotFoundException {
		File file = new File("./");
		String name = "";
		for (File f : file.listFiles()) {
			if (f.getName().endsWith(".in")) {
				name = f.getName().replaceFirst("\\.in", "");
				break;
			}
		}
		Scanner in = new Scanner(new File(name + ".in"));
		PrintWriter out = new PrintWriter(new File(name + ".out"));
		long startTime = System.nanoTime();
		new Solution(in, out);
		System.out.println("\n" + (System.nanoTime() - startTime)
				* Math.pow(10, -9) + " seconds");
		out.close();
	}

	public static class Solution {

		public Solution(Scanner in, PrintWriter out) {
			int cases = in.nextInt();
			in.nextLine();
			for (int i = 1; i <= cases; i++) {
				String answer = "Case #" + i + ": " + compute(in.nextLine());
				out.println(answer);
				System.out.println(answer);
			}
		}

		private int compute(String s) {
			Scanner sc = new Scanner(s);
			int a = sc.nextInt();
			int b = sc.nextInt();
			int digits = (a + "").length();
			HashSet<String> answer = new HashSet<String>();
			for (int shiftCount = 1; shiftCount < digits; shiftCount++) {
				for (int n = a; n <= b; n++) {
					String nString = n + "";
					String mString = nString.substring(shiftCount, digits)
							+ nString.substring(0, shiftCount);
					int m = Integer.parseInt(mString);
					if (a <= n && n < m && m <= b) {
						answer.add(nString+mString);
					}
				}
			}

			return answer.size();
		}
	}
}
