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 recycle {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			FileInputStream fstream = new FileInputStream("C:/input.txt");
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			int numOfLines = Integer.parseInt(br.readLine());	
		
			for(int i = 1; i <= numOfLines; i++){
				String str = br.readLine();
				String numbers[] = str.split(" ");
				int result = Recycle(Integer.parseInt(numbers[0]),Integer.parseInt(numbers[1]));
				System.out.println("Case #" + i + ": " + result);
				
			}
		//int A = 1111, B = 2222;
			 
			
			
	}
		catch (Exception e) {
			// TODO: handle exception
		}
}

	private static int Recycle(int A, int B) {
		// TODO Auto-generated method stub

		int j = 0, count = 0;
		for (int i = A; i <= B ; i++)
		{
			String temp = Integer.toString(i);
			ArrayList<Integer> Number = new ArrayList<Integer>();
			for (int k = 0; k < temp.length(); k++){
				
					String rotated = temp.substring(temp.length()-k, temp.length());
					String other_half = temp.substring(0, temp.length()-k);
					String total = rotated+other_half;
					int rot_number = Integer.parseInt(total);
					if(rot_number <= B && rot_number >= A && rot_number < i)
					{
						if(contains(Number, rot_number))
						{}
							//do nothing
						else{
		//					System.out.println(i + "; "+rot_number);
							Number.add(rot_number);
							count++;
						}
						
						
					}
				
			}
			
		}
		
		return count;
	}

	private static boolean contains(ArrayList<Integer> number, int rot_number) {
		// TODO Auto-generated method stub
		
		for(int i = 0; i < number.size(); i++)
		{
			if (number.get(i) == rot_number)
			{
				return true;
			}
				
		}
		
		return false;
		
	}

}
