import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

package student;

import java.io.*;
import java.util.*;

public class test {
	
	public static int getShift(String t, int pos)
	{
		int len = t.length()/2;
		return Integer.parseInt(t.substring(pos,pos+len));
	}
	
	public static void main(String[] args) throws FileNotFoundException
	{
		
		Scanner fin = new Scanner(new File("a.txt"));
		int ncase = fin.nextInt();
		
		int a=0,b=0;
		
		for(int cc = 1; cc<=ncase;cc++)
		{
			a= fin.nextInt();
			b= fin.nextInt();
			HashSet<Pair> set = new HashSet<Pair>();
			for(int i=a;i<=b;i++)
			{
				String t = (""+i) + (""+i);
				int len = t.length()/2;
				for(int j=1;j<len;j++)
				{
					int p = getShift(t, j);
					if(p>=a&&p<=b&&(""+p).length()==len && p!=i)
						set.add(new Pair(i,p));
				}
			}
			System.out.println("Case #" + cc + ": " + set.size()/2);
		}
			
	}
}
class Pair
{
	public int a,b;
	public Pair(int x,int y)
	{
		a=x;b=y;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + a;
		result = prime * result + b;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pair other = (Pair) obj;
		if (a != other.a)
			return false;
		if (b != other.b)
			return false;
		return true;
	}
}
