import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

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