import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

import java.io.BufferedReader;
import java.io.FileReader;


public class RecycledNumberTest {

	public static void main(String[] args) {
		int numCase = 0;
		int caseIndex = 0;
		int[] minValues = null;
		int[] maxValues = null;
		
		try {
			FileReader reader = new FileReader("C:\\Users\\CheeMeng\\Downloads\\C-small-attempt1.in");
			BufferedReader br = new BufferedReader(reader);
			String s = br.readLine();
			numCase = new Integer(s).intValue();
			minValues = new int[numCase];
			maxValues = new int[numCase];
			while((s = br.readLine()) != null) {
				String s1[] = s.split(" ");
				minValues[caseIndex] = new Integer(s1[0]).intValue();
				maxValues[caseIndex] = new Integer(s1[1]).intValue();
				caseIndex++;
			} 
			reader.close(); 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

//		numCase = 4;
//		minValues = new int[numCase];
//		maxValues = new int[numCase];
//		minValues[0] = 1;
//		maxValues[0] = 9;
//		minValues[1] = 10;
//		maxValues[1] = 40;
//		minValues[2] = 100;
//		maxValues[2] = 500;
//		minValues[3] = 1111;
//		maxValues[3] = 2222;

		for (int i = 1; i <= numCase; i++)  {
			System.out.println("Case #" + i + ": " + recycledTest(minValues[i - 1], maxValues[i - 1]));
		}
	}

	
	public static int recycledTest(int min, int max)  {
		int count = 0;
		int numDigits = (int) Math.ceil(Math.log10((float) max));
		
		if (numDigits == 2)  {
			for (int a0 = 1; a0 <= 9; a0++)  {
				for (int a1 = 0; a1 <= 9; a1++)  {
					if (a0 < a1)  {
						int actualNum = 10 * a0 + a1;
						int recycledNum = 10 * a1 + a0;
						if ((actualNum >= min) && (actualNum <= max) && (recycledNum >= min) && (recycledNum <= max) && (actualNum < recycledNum))  {
							count++;
						}
					}
				}
			}
		}
		else if (numDigits == 3)  {
			for (int a0 = 1; a0 <= 9; a0++)  {
				for (int a1 = 0; a1 <= 9; a1++)  {
					for (int a2 = 0; a2 <= 9; a2++)  {
						int actualNum = 100 * a0 + 10* a1 + a2;
						int recycledNum = 100 * a1 + 10 * a2 + a0;
						if (a1 > 0)  {
							if ((actualNum >= min) && (actualNum <= max) && (recycledNum >= min) && (recycledNum <= max) && (actualNum < recycledNum))  {
								count++;
							}
						}
						recycledNum = 100 * a2 + 10 * a0 + a1;
						if (a2 > 0)  {
							if ((actualNum >= min) && (actualNum <= max) && (recycledNum >= min) && (recycledNum <= max) && (actualNum < recycledNum))  {
								count++;
							}
						}
					}
				}
			}
		}
		
		return count;
	}	
}
