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

			}
		}

	}
}

package google.contest.C;

import google.loader.Challenge;
import google.problems.AbstractChallenge;

import java.util.HashSet;
import java.util.Set;

public class CChallenge extends AbstractChallenge implements Challenge {

	private int B;
	private int A;
	private int num;
	Set<String>pairs ;
	public CChallenge(int number, String line) {
		super(number);
		num=0;
		
		pairs = new HashSet<String>();
		
		String[] tokens = line.split(" ");

		A = Integer.parseInt(tokens[0]);
		B = Integer.parseInt(tokens[1]);
		int i=0;
		for( i=A ; i<=B; i++){
			calcFor(i);
		}
		
		setResult(""+num);
	}

	private void calcFor(int i) {
		String numString = ""+i;
		
		for(int j=1; j<= numString.length()-1; j++){
			String first = numString.substring(0,j);
			String second = numString.substring(j);
			String third = second+first;
			check(i, third);
			
		}
	}

	private void check(int i, String third) {
		if(third.startsWith("0")){
			return;
		}
		int j = Integer.parseInt(third);
		if(A<=i && i<j && j<=B){
			
			String hlp = ""+i+j;
			if(! pairs.contains(hlp)){
				pairs.add(hlp);
				num++;
			}else{
				System.out.println(""+num+"  "+i+"  "+j);
			}
		}
	}
}
