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 com.forbeck.codejam2012;

import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class ProblemC {

	private static final String OUTPUT = "resources/codejam2012/c/C-small-attempt1.out";
	private static final String INPUT = "resources/codejam2012/c/C-small-attempt1.in";

	private static List<String> recycleds;

	public static void main(String[] args) throws IOException {
		final BufferedReader br = new BufferedReader(new FileReader(INPUT));
		final BufferedWriter bw = new BufferedWriter(new FileWriter(OUTPUT));
		final Integer tcs = Integer.parseInt(br.readLine());

		int count = 1;
		while (count <= tcs) {
			recycleds = new ArrayList<String>();

			final StringTokenizer st = new StringTokenizer(br.readLine());
			final String a = st.nextToken(), b = st.nextToken();
			
			for (int m = parseInt(a) + 1; m <= parseInt(b); m++) {
				for (int n = parseInt(a); n < m; n++) {
					verifyRecycled(String.valueOf(n), String.valueOf(m));
				}
			}
			
			out(bw, count++);
		}

		bw.close();
	}

	private static void out(final BufferedWriter bw, int count) throws IOException {
		bw.write("Case #" + count + ": " + recycleds.size() + "\n");
	}

	private static void verifyRecycled(String N, String M) {
		if (N.length() != M.length() || M.length() == 1 || N.length() == 1)
			return;

		for (int i = N.length() - 1; i > 0; i--) {
			final String moved = N.substring(i);

			final String suposedM = moved + N.substring(0, N.lastIndexOf(moved));
			if (!M.equals(suposedM)) 
				continue;
			
			
			 if (!recycleds.contains(N + M)) {
				 recycleds.add(N + M);
			} 
		}
	}
	
}