import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
package com.monochromeiguana.codejam;

import com.google.common.collect.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * Hello world!
 *
 */
public class Main {

    static BufferedReader in;
    static BufferedWriter out;
    static String inputFile = "in.txt";
    static String outputFile = "outfile.txt";

    private static class Parser {

        public final int index;
        public final int answer;
        public final int lBound;
        public final int uBound;

        public Parser(String line, int ix) {
            index = ix;
            List<String> parts = Arrays.asList(line.split(" "));
            lBound = Integer.parseInt(parts.get(0));
            uBound = Integer.parseInt(parts.get(1));

            Multimap<String, String> out = ArrayListMultimap.create();
            for (int l = lBound; l < uBound; l++) {
                String thing = String.valueOf(l);
                Set<String> friends = Sets.newHashSet();
                for (int offset = 1; offset < thing.length(); offset++) {
                    String friend = thing.substring(offset).concat(thing.substring(0, offset));
                    if (friend.startsWith("0")) {
                        continue;
                    }
                    
                    int friendly = Integer.parseInt(friend);
                    if (friendly <= l || friendly > uBound) {
                        continue;
                    }
                    friends.add(friend);
                }
                out.putAll(thing, friends);
            }
            answer = out.values().size();
        }

        public String output() {
            return "Case #" + index + ": " + answer;
        }
    }

    public static void main(String[] args) throws Exception {

        in = new BufferedReader(new FileReader(inputFile));
        out = new BufferedWriter(new FileWriter(outputFile));
        try {
            String line = in.readLine();
            int nbCases = Integer.parseInt(line);
            int index = 0;
            while ((line = in.readLine()) != null) {
                index++;
                Parser p = new Parser(line, index);
                out.write(p.output());
                out.newLine();
            }
        } finally {
            in.close();
        }
        out.flush();
    }
}
