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.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution3 {
	
	public static void main(String[] args) throws Exception {
		System.out.println(
			parseOfFile(new File("C:\\code\\teste.txt"))
		);
	}
	
	public static String parseOfFile(File file) throws Exception {
		FileInputStream fstream = new FileInputStream(file);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		StringBuffer sb = new StringBuffer();

		String strLine;
		while ((strLine = br.readLine()) != null) {
			sb.append(strLine.trim());
			sb.append("\n");
		}

		return parser(sb.toString());
	}
	
	public static String parser(String string) {
		String[] lines = string.split("\n");
		StringBuffer sb = new StringBuffer();
		
		for (int index = 1; index < lines.length; index++) {
			String[] values = lines[index].split(" ");
			int a = Integer.parseInt(values[0]);
			int b = Integer.parseInt(values[1]);
			
			sb.append("Case #");
			sb.append(index);
			sb.append(": ");
			sb.append(quantidade(a, b));
			
			if (index != lines.length - 1) sb.append("\n");
		}
		
		return sb.toString();
	}
	
	public static int quantidade(int a, int b) {
		List<Integer> availablesNumbers = new ArrayList<Integer>();
		Set<Pair> pairs = new HashSet<Pair>();
		
		for (int number = a; number <= b; number++) 
			availablesNumbers.add(number);
		
		for (Integer integer : availablesNumbers) {
			String string = integer.toString();
			for (int index = 1; index <= string.length(); index++) {
				String newString = string.substring(index) + string.substring(0, index);
				Integer newNumber = Integer.parseInt(newString);
				
				if (!availablesNumbers.contains(newNumber)) continue;
				if (integer.equals(newNumber)) continue;
				if (integer < newNumber) continue;
				
				pairs.add(new Pair(integer, newNumber));
			}
		}
		
		return pairs.size();
	}
	
	public static class Pair {
		Integer a;
		Integer b;
		
		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
		
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((a == null) ? 0 : a.hashCode());
			result = prime * result + ((b == null) ? 0 : b.hashCode());
			return result;
		}
		
		@Override
		public boolean equals(Object obj) {
			if (obj.getClass() != Pair.class) return false;
			Pair other = (Pair) obj;
			
			if (other.a.equals(a) && other.b.equals(b)) return true;
			if (other.a.equals(b) && other.b.equals(a)) return true;
			if (other.b.equals(a) && other.a.equals(b)) return true;
			
			return false;
		}
		
		@Override
		public String toString() {
			return "[ " + a + ", " + b + " ]";
		}
	}

}
