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.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(new File("input.txt"));
		
		int testcases = in.nextInt();
		int a, b, count;
		String aString, bString;
		ArrayList<String> compList = new ArrayList<String>();
		
		for(int test=1; test<=testcases; test++)
		{
			a = in.nextInt();
			b = in.nextInt();
			count = 0;
			
			while(a<b)
			{
				compList = new ArrayList<String>();
				aString = String.valueOf(a);
				
				for(int i=1; i<aString.length(); i++)
				{
					compList.add(aString.substring(aString.length()-i, aString.length())+aString.substring(0,aString.length()-i));
				}
				
				for(int i=a+1; i<=b; i++)
				{
					bString = String.valueOf(i);
					
					for(String s : compList)
					{
						if (bString.equals(s) && s.indexOf("0")!=0)
						{
							count++;
						}
					}
				}
				a++;
			}
			
			System.out.println("Case #"+test+": "+count);
			
		}

	}

}
