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.*;
class ProbC
{
	String calculate(int low,int up)
	{	String ans="";
		int anscount=0;
		int l=low;
		int u=up;
		for(int i=l;i<=u;i++)
		{
				String num=Integer.toString(i);
				for(int j=1;j<num.length();j++)
				{
					String first=num.substring(0,j);
					String second=num.substring(j,num.length());
					String now=second+first;
					//System.out.println(now);
					if(now.charAt(0)=='0')
					{
						
					}
					else
					{
						int comp=Integer.parseInt(now);
						if(comp<=up&&i<comp)
						{
							anscount=anscount+1;
						}
					}
			}
		}
	
				return Integer.toString(anscount);
	}

	public static void main(String args[]) 
	throws IOException 
	{
		ProbC obj=new ProbC();
		
		File ii = new File ("C-small-attempt0.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("ProbCoutputsmall.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		
		for(int i=0;i<cases;i++)
		{
			String temp1 = br.readLine();
			String parts [] = temp1.split(" ");
			
			int low=Integer.parseInt(parts[0]);
			int up=Integer.parseInt(parts[1]);
			int uc=0,lc=0;
			int temp=low;
			while(temp>0)
			{
				int a=temp%10;
				temp=temp/10;
				uc++;
			}
			temp=low;
			while(temp>0)
			{
				int a=temp%10;
				temp=temp/10;
				lc++;
			}
			if(uc==lc)
			{
				System.out.println("A and B have same number of digits");
				String result=obj.calculate(low,up);
				String finalans="Case #"+(i+1)+":  "+result+System.getProperty("line.separator");
				dout.writeBytes(finalans);
			}
			else
			{
				System.out.println("A and B do not have same number of digits");
			}
		
		}
	}
}