import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Q3M {
	public static void main(String[] args) throws Exception {
		compute();
	}

	private static void compute() throws Exception {
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"C:\\work\\Q3\\C-small-attempt0.in")));
		String line = null;
		int i = Integer.parseInt(br.readLine());
		List l = new ArrayList();
		for (int j = 0; j < i; j++) {
			line = br.readLine();
			String[] nums = line.split(" ");
			l.add(calculate(nums));
		}
		writeOutput(l);
	}

	private static int calculate(String[] nums) {
		int min = Integer.parseInt(nums[0]);
		int max = Integer.parseInt(nums[1]);
		int count = 0;
		List l = new ArrayList();
		for (int i = min; i <= max; i++) {
			for (int times = 1; times < countDigits(i); times++) {
				int res = shiftNum(i, times);
				if (res <= max && i < res) {
					if ((!l.contains((i + ":" + res)))) {
						l.add(i + ":" + res);
						l.add(res + ":" + i);
						count++;
					}
				}
			}
		}
		return count;
	}

	private static boolean checkZeros(int temp, int res) {
		if (temp % 10 == 0 || res % 10 == 0)
			return false;
		return true;
	}

	private static int shiftNum(int n, int times) {
		int base = (int) Math.pow(10, times);
		int temp2 = n / base;
		int placeHolder = (int) Math.pow((double) 10,
				(double) countDigits(temp2));
		int res = placeHolder * (n % base) + temp2;
		if (countDigits(res) == countDigits(n)) {
			return res;
		} else {
			return 2000001;
		}
	}

	public static int countDigits(int x) {
		if (x < 10)
			return 1;
		else {
			return 1 + countDigits(x / 10);
		}
	}

	private static void writeOutput(List l) throws Exception {
		StringBuffer b = new StringBuffer();
		int i = 1;
		BufferedWriter br = new BufferedWriter(new FileWriter(new File(
				"C:\\work\\Q3\\ans.txt")));
		for (Iterator iterator = l.iterator(); iterator.hasNext();) {
			br.write("Case #" + i++ + ": " + iterator.next());
			br.newLine();
		}
		br.close();
	}

}

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author JY
 */
public class ProblemC4Test {

    private static int testNum;
    private static int[][] data;
    private static final int EQUAL = 0;
    private static final int LESS = 1;
    private static final int LARGER = 2;

    public static void main(String[] args) {
        input();
        int[] result = calc();
        output(testNum, result);
    }

    private static void input() {
        Scanner in = null;

        String file = "C-small-attempt0.in";
        try {
            in = new Scanner(new FileInputStream(file));
        } catch (FileNotFoundException ex) {
            System.out.println("Error reading file.");
            System.exit(0);
        }

        //in = new Scanner(System.in);
        testNum = Integer.parseInt(in.nextLine());
        data = new int[testNum][];
        for (int i = 0; i < testNum; i++) {
            String line = in.nextLine();
            String[] nums = line.split(" ");
            data[i] = new int[2];
            data[i][0] = Integer.parseInt(nums[0]);
            data[i][1] = Integer.parseInt(nums[1]);
        }
    }

    private static int[] calc() {
        HashSet<Integer> hs = new HashSet<Integer>();
        int[] res = new int[testNum];
        for (int i = 0; i < testNum; i++) {
            int result = 0;
            int a = data[i][0];
            int b = data[i][1];
            int length = getLength(b);;
            for (int number = a; number <= b; number++) {
                hs.clear();
                for (int shifts = 1; shifts < length; shifts++) {
                    int shiftnum = shift(number, shifts);
                    if (shiftnum <= b && shiftnum > number && !hs.contains(shiftnum)) {
                        result++;
                        hs.add(shiftnum);
                    }
                }
            }
            res[i] = result;
        }
        return res;
    }

    private static int getLength(int n) {
        return String.valueOf(n).length();
    }

    private static int shift(int num, int shift) {
        String numS = String.valueOf(num);
        int len = numS.length();
        numS = reverse(numS, 0, len - shift - 1);
        numS = reverse(numS, len - shift, len - 1);
        numS = reverse(numS, 0, len - 1);
        return Integer.parseInt(numS);
    }

    private static String reverse(String target, int start, int end) {
        char[] tar = target.toCharArray();
        while (start < end) {
            char tmp = tar[start];
            tar[start] = tar[end];
            tar[end] = tmp;
            start++;
            end--;
        }
        return new String(tar);
    }

    private static void output(int testNum, int[] res) {
        for (int i = 0; i < testNum; i++) {
            System.out.printf("Case #%d: %s\n", i + 1, res[i]);
        }
    }
}
