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 lt.kasrud.gcj.common;


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IO {
  public static Data readFile(String filename) throws IOException {
    Data results = new Data();

    BufferedReader reader = new BufferedReader(new FileReader(filename));
    String line = null;
    while ((line = reader.readLine()) != null) {
      results.add(new Record(line));
    }

    reader.close();
    return results;
  }

  private static String formatCase(int caseNr, String output) {
    return String.format("Case #%d: %s", caseNr, output);
  }

  public static void writeFile(String filename, List data) throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
    for (int i = 0; i < data.size(); i++) {
      String output = formatCase(i + 1, data.get(i).toString());
      writer.write(output + "\n");
    }
    writer.close();
  }

  public static class Data {
    List<Record> records = new ArrayList<Record>();

    public void add(Record record){
      records.add(record);
    }

    public String getString(int recNr, int i){
      Record record = records.get(recNr);
      return record.getString(i);
    }

    public Integer getInt(int recNr, int i){
      Record record = records.get(recNr);
      return record.getInt(i);
    }

    public List<Record> getRecords(int from){
      return getRecords(from, records.size());
    }

    public List<Record> getRecords(int from, int to){
      return records.subList(from, to);
    }

  }

  public static class Record {
    String raw;
    String[] tokens;

    Record(String raw) {
      this(raw, " ");
    }

    Record(String raw, String separator) {
      this.raw = raw;
      tokens = raw.trim().split(separator);
    }

    public String getRaw() {
      return raw;
    }

    public String getString(int i) {
      return tokens[i];
    }

    public int getInt(int i) {
      return Integer.valueOf(getString(i));
    }

    public List<String> getStringList(int from){
      return getStringList(from, tokens.length);
    }

    public List<String> getStringList(int from, int to){
      return Arrays.asList(tokens).subList(from, to);
    }

    public List<Integer> getIntList(int from){
      return getIntList(from, tokens.length);
    }

    public List<Integer> getIntList(int from, int to){
      List<String> strings = Arrays.asList(tokens).subList(from, to);
      List<Integer> ints = new ArrayList<Integer>(strings.size());
      for (String s : strings){
        ints.add(Integer.valueOf(s));
      }
      return ints;
    }
  }
}
