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));
	}
}

package c;
import java.io.*;
/**
 * Google Code Jam C
 * @author hang
 *
 */

public class Main {
	public static void main(String args[]) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String n_str = br.readLine();
		int n_int = Integer.parseInt(n_str);
		int min, max;
		for(int i = 1;i<=n_int;i++)
		{
			String []s = br.readLine().split("\\s");
			int length = s[0].length();
			min = Integer.parseInt(s[0]);
			max = Integer.parseInt(s[1]);
			if(max<10)
			{
				System.out.println("Case #" + i + ": " + 0);
				continue;
			}
		    
			int number = 0;
			
			int multiple_base = 1;
			for(int j = 1;j<length;j++)
				multiple_base*=10;
			for(int k = min;k<max;k++)
			{
				int multiple_increase = 1;
				int multiple_decrease = multiple_base;
				for(int j = 1;j<=length-1;j++)
				{
					multiple_increase*=10;
					int new_number = (k/multiple_increase) + (k%multiple_increase)*multiple_decrease;
					if(new_number>k&&new_number<=max)
						number++;
					multiple_decrease/=10;
				}
			}
			System.out.println("Case #" + i + ": " + number);
			
		}
	}
}
