import java.io.*;
import java.util.*;

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

package com.codejam.practice;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Recycled {
	public static void main(String[] args) {
		//File read & write variables
		File inputFile = new File("C:/Users/SNALLAMA/Desktop/C-large.in");
		File outputFile = new File("C:/Users/SNALLAMA/Desktop/C-large.out");
		String line = null;
		int t, a, b, noOfDigits, divider, localnumber;
		//long outNumber=0;
		Set<String> finalOP = new HashSet<String>();		
		
		try {
			BufferedReader bReader =  new BufferedReader(new FileReader(inputFile));
			BufferedWriter bWriter = new BufferedWriter(new FileWriter(outputFile));
			try {
				t = Integer.parseInt(bReader.readLine().trim());
				//System.out.println("No. Of Cases"+t);
				for(int index=0;index<t;index++) {
					line = bReader.readLine().trim();
					StringTokenizer st = new StringTokenizer(line, " ");
					a=Integer.parseInt(st.nextElement().toString());
					b=Integer.parseInt(st.nextElement().toString());
					noOfDigits=String.valueOf(a).length();
					finalOP=new HashSet<String>(); 
					if(noOfDigits!=1){						
						for(int i=a;i<=b;i++){
							for(int localIndex=1;localIndex<noOfDigits;localIndex++){
								divider=Integer.parseInt(String.valueOf((int)Math.pow(10, localIndex)));
								localnumber=Integer.parseInt(String.valueOf(i%divider)+String.valueOf(i/divider));
								if((String.valueOf(localnumber).length()==String.valueOf(i).length())&&(a<=i)&&(i<localnumber)&&(localnumber<=b)){
									if(!finalOP.contains(localnumber+" "+i))
										finalOP.add(i+" "+localnumber);
									//System.out.println(divider+" "+i);
								}
							}
						}
					}
					
					bWriter.write("Case #"+(index+1)+": "+finalOP.size());
					bWriter.write("\n");					
				}
			} catch(Exception e) {
				System.out.println("Exception Message: "+ e.getMessage());
				e.printStackTrace();
			}finally{
				bReader.close();
				bWriter.close();
			}
			
		} catch(Exception e) {
			System.out.println("Exception Message: "+ e.getMessage());
			e.printStackTrace();
		} 				
	}

}
