import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int caze, T;
	int A, B;

	void run(){
		T=sc.nextInt();
		for(caze=1; caze<=T; caze++){
			A=sc.nextInt();
			B=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int n=A; n<=B; n++){
			int digit=(int)(log10(n)+EPS);
			int d=(int)pow(10, digit);
			// debug("n", n);
			for(int m=rot(n, d); m!=n; m=rot(m, d)){
				// debug("m", m);
				if(n<m&&m<=B){
					ans++;
				}
			}
		}
		answer(ans+"");
	}

	int rot(int n, int d){
		return n/10+n%10*d;
	}

	void answer(String s){
		println("Case #"+caze+": "+s);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		try{
			System.setIn(new FileInputStream("dat/C-small.in"));
			System.setOut(new PrintStream(new FileOutputStream("dat/C-small.out")));
		}catch(Exception e){}
		new C().run();
		System.out.flush();
		System.out.close();
	}
}

package files;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Hashtable;

public class Recycle2 {
	public static void main(String[] args)
	{
		try
		{
			String line;
			String data="";
			 File ff = new File("Output.txt");
		     if (ff.exists())
		     {
		    	 ff.delete();
			 }
		     //BufferedReader br = new BufferedReader(new FileReader("/Users/Sush/Documents/workspace1/CJ/src/files/Input.txt"));
		     BufferedReader br = new BufferedReader(new FileReader("/Users/Sush/Downloads/C-small-attempt2.in.txt"));
			 
			 StringBuffer sb = new StringBuffer();
				 while((line = br.readLine())!= null)
				 {
					 sb = sb.append(line +"\n");
				 }
			 String[] nos = sb.toString().split("\n");
			 for (int i = 1; i< nos.length; i++)
			 {
		     Hashtable<Integer, Integer> counts = new Hashtable<Integer, Integer>();
		     //System.out.println("Str "+nos[i]);
			 String[] num = nos[i].split(" ");
			 int count=0;
		     int begin=Integer.parseInt(num[0]);
		     int end = Integer.parseInt(num[1]);
		     while(begin < end)
		     {
		    	 int a = begin;
		    	 int d = (int)Math.floor(Math.log10(a));
		    	 
		    	 if (d!= 0)
		    	 {
		    	 int f = a/(int)(Math.pow(10, d));
		    	 int n = a/(int)(Math.pow(10, d-1));
		    	 if (f>n)
		    	 {
		    		 a = f * (int)Math.pow(10, d) + n * (int)Math.pow(10, d-1); 
		    	 }
		    	 }
		    	 int check = a;
		    	 int x = 0; 
		     if (!counts.containsKey(a))
		     {
		    	 counts.put(a, 0);
			     while(x != a)
			     {
			    	 x = (check%10)*(int)(Math.pow(10.0, d)) + (check/10);
			    	 check = x;
			    	 if (x > a && x <= end)
			    	 {
			    		 //counts.put(x, 0);
			    		 count = count +1; 
			    		 counts.put(a, count);
			    	 }
			     }
		     }
		     begin = begin + 1;
		     }
		     data = data + "Case #"+i+": "+count+"\n";
		     System.out.print("Case #"+i+": ");
		     System.out.println(count);
		     
		}

	     BufferedWriter bw = new BufferedWriter(new FileWriter(ff, true));
	     bw.write(data);
	     bw.close();
		}
		catch(Exception e)
		{
			System.out.println(e);
		}
	}
}
