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 codejam;

import java.io.File;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Scanner;


public class QualificationC {
	public static long recycled(long nr1,long b){
		long count=0;
		String n1=String.valueOf(nr1);
		String n2=n1;
		HashMap<String,Boolean> gen=new HashMap<String,Boolean>();
		for(int i=0;i<n2.length();i++){
			n2=n2.substring(1,n2.length())+n2.substring(0,1);
			if(gen.containsKey(n2))continue;
			else gen.put(n2,Boolean.TRUE);
			long nr2=Long.parseLong(n2);
			if(String.valueOf(nr2).length()!=n1.length())continue;
			if(nr2>nr1&&nr2<=b){
				count++;
			}
		}
		return count;
	}
	public static void main(String[] args){
		try{
			Scanner sc=new Scanner(new File("C.in"));
			PrintStream ps=new PrintStream("C.out");
			int n=sc.nextInt();
			long a,b;
			for(int i=0;i<n;i++){
				long count=0;
				a=sc.nextLong();
				b=sc.nextLong();
				for(long nr1=a;nr1<b;nr1++)
					count+=recycled(nr1,b);
				ps.println("Case #"+(i+1)+": "+count);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
