import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
package com.problemC;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

class RecyclePair {

	int n, m;

	public RecyclePair(int a, int b) {
		assert (a < b);
		n = a;
		m = b;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof RecyclePair) {
			RecyclePair o = (RecyclePair) obj;
			if (this.n == o.n && this.m == o.m)
				return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return n * m;
	}

}

public class RecycledNumber {

	private static int A = 1111;
	private static int B = 2222;
	public static int count = 0;
	static Set<RecyclePair> pairs = null;

	public static void main(String[] args) {
		String[] s;
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(
					"src/com/problemC/C-large.in"));
			// br = new BufferedReader(
			// new FileReader("src/com/problemC/input.txt"));
			int caseNo = 1;
			int T = Integer.parseInt(br.readLine());
			while (caseNo <= T) {
				count = 0;
				pairs = new HashSet<RecyclePair>();
				s = br.readLine().split(" ");
				A = Integer.parseInt(s[0]);
				B = Integer.parseInt(s[1]);
				for (int i = A; i < B; i++) {
					rotate(i);
				}
				System.out.println("Case #" + caseNo++ + ": " + pairs.size());
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
	}

	private static void rotate(int num) {
		int l = (num + "").length(), l2;
		int toCut = 1;
		int original = num, newNum;
		String s = num + "", firstPart, secondPart;
		// if(num%10==0) return;
		// System.out.println("");
		// System.out.println("Original Number in question: " + s);
		for (toCut = 0; toCut <= l; toCut++) {
			firstPart = s.substring(0, l - toCut);
			secondPart = s.substring(l - toCut);
			newNum = Integer.parseInt(secondPart + firstPart);
			// System.out.println(firstPart + " " + secondPart + ": " + newNum);
			l2 = (newNum + "").length();
			if (l == l2 && (original < newNum && newNum <= B)) {
				RecyclePair rp = new RecyclePair(original, newNum);
				if (!pairs.add(rp)) {
					// System.out.println("NO ***********************************************");
				}
				// System.out.println("YES : " + original + " " +
				// newNum+" "+count);
				// System.out.println("");
				count++;
			}
		}
	}
}
