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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;


public class ProbB {

	/**
	 * @param args
	 * @throws IOException 
	 */
	
	public static HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader inputStream;
		PrintWriter outputStream;
		try {
			inputStream = new BufferedReader(new FileReader("X:\\GCJ\\input.txt"));
			outputStream = new PrintWriter(new BufferedWriter(new FileWriter("X:\\GCJ\\output.txt")));


			int n=Integer.parseInt(inputStream.readLine()),z=0;
			
			while(n>0)
			{
				n--;z++;c=0;
				String s=inputStream.readLine();
				int spc= s.indexOf(' ');
				int r=0,A=Integer.parseInt(s.substring(0,spc)),B=Integer.parseInt(s.substring(spc+1));
				
				for (int i = A; i < B; i++) {
					func(i,A,B,digits(A));
					
				}
				
				
				outputStream.println("Case #"+z+": "+c);
				System.out.println("Case #"+z+": "+c);
			}
			
			outputStream.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println("File not found.");
			e.printStackTrace();
		}
	}

	public static int digits(int a) {
		int z=0;
		while(a!=0){
			a/=10;z++;
		}
		return z;
	}
	
	public static int c=0;
	
	public static void func(int a,int A,int B, int n){
		int a2=0;
		int o=a;
		
		for (int j = 1; j < n; j++) {
			
			int k=a%10;
			for (int i = 0; i < n-1; i++) {
				k*=10;
			}
			a2= k+a/10;
								
			if(a2>o && a2<=B){
				map.put(o,a2);c++;
				System.out.println(c+":"+o+","+a2);
			}
			
			
			a=a2;
		}
		
	}
	
}
