package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.Scanner;


public class RecycledNumbers {

	public static int getlength(int number)
	{
		int size = 1;
		number = number/10;
		while (number!=0)
		{
			size++;
			number = number/10;
		}
		
		return size;
	}
	
	public static void main(String[] args) throws FileNotFoundException {
		
		Scanner s = new Scanner (new File("C-small-attempt0.in")); 
//				(System.in);
		int i = s.nextInt();
		int a,b,sa,c,cnt,r;
		LinkedList<Integer> ll;
		for(int j = 0 ;  j < i ; j++)
		{
			a = s.nextInt();
			b = s.nextInt();
			sa = getlength(a);
			cnt = 0;
			for( int k = a ; k <= b; k++)
			{
				r = k;
				ll = new LinkedList<Integer>();
				if(getlength(r)>1)
				for (int l = 0 ; l < sa-1 ; l++)
				{
					c = r/(int)Math.pow(10, sa-1);
					r = (r-c*(int)Math.pow(10, sa-1))*10+c;
					if(r<=b&&r>k&&!ll.contains(r))
					{
					ll.add(r);	
					cnt++;
					}
				}
			}
			System.out.println("Case #"+(j+1)+": "+(cnt));
		}
		
		
	}
	
}
