import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;
	
	public static void main(String[] args) throws IOException
	{
		new Main().execute();
	}
	
	void debug(Object...os)
	{
		System.out.println(Arrays.deepToString(os));
	}
	
	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}
	
	long nl() throws IOException 
	{
		return Long.parseLong(ns());
	}
	
	double nd() throws IOException 
	{
		return Double.parseDouble(ns());
	}
		
	String ns() throws IOException 
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens()) 
			tokenizer = new StringTokenizer(br.readLine());
		return tokenizer.nextToken();
	}
	
	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}
		
	
	//Main Code starts Here
	int totalCases, testNum;	
	
	void execute() throws IOException
	{
		totalCases = ni();
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			input();
			System.out.print("Case #"+testNum+": ");
			solve();
		}
	}
	class Pair implements Comparable<Pair>
	{	
		int a,b;
		Pair(int _a,int _b)
		{
			a=_a;
			b=_b;
		}
		
		public int compareTo(Pair x)
		{
			if(a == x.a) return b-x.b;
			return a-x.a;
		}
		
		public boolean equals(Pair x)
		{
			return a==x.a && b==x.b;
		}
		
		public String toString()
		{
			return "("+a+","+b+")";
		}
	}

	HashSet<Integer> m;
	void solve()
	{
		int count = 0;
		for(int i=a;i<=b;i++)
		{
			m = new HashSet<Integer>();	
			String s = Integer.toString(i);
			int l = s.length();
			for(int j=0;j<l;j++)
			{
				String t ="";				
				t = s.substring(j,l)+s.substring(0,j);
				int n = Integer.parseInt(t);
				if(n>i && n<=b)
					m.add(n);
			}
			count+=m.size();
		}
		System.out.println(count);
		System.err.println(count);
				
	}
	
	void printarr(int [] a,int b)
	{
		for(int i = 0;i<=b;i++)
		{
			if(i==0)
				System.out.print(a[i]);
			else
				System.out.print(" "+a[i]);
		}
		System.out.println();
	}
	int a,b;
	boolean input() throws IOException
	{
		a=ni();
		b=ni();
		return true;
	}
}