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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class GoogleC {

	public static void main(String[] args) throws FileNotFoundException{
		Scanner scan = new Scanner(new File("B-small.txt"));
		//finit2();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++){
			ht.clear();
			System.out.println("Case #" + (i+1) + ": " + sum(scan.nextInt(), scan.nextInt()));
		}
	}

	public static long sum(int a, int b){
		ht = new HashSet<Pair>();
		long ret = 0;
		for (int i = a; i <= b; i++){
			ret += run(i, a, b);

		}
		return ret;
	}

	public static HashSet<Pair> ht = new HashSet<Pair>();

	private static class Pair{
		int m, n;
		public Pair(int m, int n){
			this.m = m;
			this.n =n;
		}
		public int hashCode(){
			return 31*m+n;
		}

		@Override
		public boolean equals(Object o){
			Pair p = (Pair)o;
			return p.m == m && p.n == n;
		}
	}

	public static int run(Integer n, int a, int b){

		int count = 0;
		String orig = n.toString();
		String cur = n.toString();
		
		for (int i = 0; i < orig.length()-1; i++){
			char c = cur.charAt(0);

			cur = cur.substring(1) + c;
			if (cur.charAt(0) == '0') continue;
			int k = Integer.parseInt(cur);

			if (a <= k && k < n){
				
				if (cur.length()%2==0 && cur.substring(0, cur.length()/2).equals(cur.substring(cur.length()/2, cur.length()))){
					Pair p = new Pair(k, n);
					if (!ht.contains(p)){
						count++;
						//System.out.println(k + " " + n);
						ht.add(p);
					}
					/*else{
						System.out.println(k + " " + n);
					}*/
				}
				else{
					count++;
				}
				
			}
			
		}
		return count;

	}


}
