import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
import java.util.*;
import java.io.*;
public class C
{
	List<String> arrList ;
	public void readFile(String srcFileName, String destFileName)
	{
		try
		{
			File srcFile = new File(srcFileName);
			File destFile = new File(destFileName);
			BufferedReader br = new BufferedReader(new FileReader(srcFile));
			BufferedWriter bw = new BufferedWriter(new FileWriter(destFile));
			int cases = Integer.parseInt(br.readLine());
			//cases =1;
			for(int i=0;i<cases;i++)
			{
				int counter =0;
				String lineInfo[] = br.readLine().split(" ");
				int firstNum = Integer.parseInt(lineInfo[0]);
				int secondNum = Integer.parseInt(lineInfo[1]);
				arrList= new ArrayList<String>();
				for(int k=firstNum;k<=secondNum;k++)
				{
					char[] ch = (k+"").toCharArray();
					for(int j =0; j<ch.length;j++)
					{
						ch = rotate(ch);
						int check = arrToString(ch);
					//	System.out.println(check);
						if(check != k && firstNum!=check && check!=secondNum)
						{
							if(firstNum<check && check<secondNum)
							{
								String sa = k+"-"+check;
								String sb = check+"-"+k;
								if(!arrList.contains(sa)&& !arrList.contains(sb))
								{
									arrList.add(sa);
									arrList.add(sb);
									counter++;
								}
							}
						}
					}
				}
				String str = "Case #"+(i+1)+": "+counter;
				bw.write(str);
				bw.newLine();
			}
			br.close();
			bw.close();
			
		}
		catch(Exception e)
		{
			System.out.println("Exception");
		}
	}
	
	public char[] rotate(char[] ch)
	{
		char temp = ch[0];
		for(int j=1;j<ch.length;j++)
		{
			ch[j-1]=ch[j];
		}
		ch[ch.length-1] = temp;
		return ch;
	}
	
	public int arrToString(char[] ch)
	{
		String str = "";
		for(int i=0;i<ch.length;i++)
		{
			str= str+ch[i];
		}
		return Integer.parseInt(str);
	}
	
	public static void main(String args[])
	{
		C c = new C();
		c.readFile(args[0],args[1]);
	}
}