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 com.edwarddrapkin;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Numbers {
	
	private boolean isRecylced(int m, int n) {
		String sm = m + "";
		String sn = n + "";
		
		//eliminate some common cases
		
		// same number apparently doesn't count...
		
		if(sm.equals(sn)) {
			return false;
		}
		
		//not the same length
		while(sm.length() < sn.length()) {
			sm = "0" + sm;
		}
		
		while(sn.length() < sm.length()) {
			sn = "0" + sn;
		}
		
		//chars in m not in n
		for(char c : sm.toCharArray()) {
			if(!sn.contains("" + c)) {
				return false;
			}
		}
		
		//vice versa
		for(char c : sn.toCharArray()) {
			if(!sm.contains("" + c)) {
				return false;
			}
		}
		
		for(int i = 1; i < sm.length(); i++) {
			String slice = sm.substring(i) + sm.substring(0, i);
			if(slice.equals(sn)) {
				return true;
			}
		}
		
		return false;
	}
	
	private static String[] readFile(String file) throws IOException {
		Scanner scanner = new Scanner(new File(file));
		
		String numLines = scanner.nextLine();
		
		int nl = Integer.parseInt(numLines);
		
		String[] lines = new String[nl];
		int i = 0;
		
		while(scanner.hasNextLine() && i < nl) {
			lines[i] = scanner.nextLine();
			++i;
		}
		
		return lines;
	}
	
	public static void main(String[] args) throws Exception {
		Numbers num = new Numbers();

		String[] lines = readFile("C:/Users/Eddie/Desktop/google_input.txt");
		
		int i = 1;
		for(String line : lines) {
			Scanner lScanner = new Scanner(line);
			int low = lScanner.nextInt();
			int high = lScanner.nextInt();
			
			int numPossible = 0;
			for(int idx = low; idx <= high; idx++) {
				for(int inner = idx; inner <= high; inner++) {
					if(num.isRecylced(idx, inner)) {
						//System.out.println(high + " " + low + " " + idx + " " + inner);
						numPossible++;
					}
				}
				
			}
			
			System.out.println("Case #" + i + ": " + numPossible);
			i++;
		}
	}
}













