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

}
package com.forthgo.google.g2012r0;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by Xan Gregg.
 * Date: 4/14/12
 */
public class ProblemC {
    public static void main(String[] args) {
        try {
            Scanner in = new Scanner(new File("C.in"));
            PrintWriter out = new PrintWriter(new FileWriter("C.out"));
            //PrintWriter out = new PrintWriter(System.out);
            int t = in.nextInt();
            for (int i = 0; i < t; i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                int k = solve(a, b);
                out.printf("Case #%d: %d%n", i + 1, k);
                out.flush();
            }

        } catch (IOException e) {
            throw new RuntimeException();
        }

    }

    private static int solve(int a, int b) {
        int k = 0;
        int nda = (int) (Math.log10(a) + 1);
        int ndb = (int) (Math.log10(b) + 1);
        Set<Long> pairs = new HashSet<Long>(b - a);
        for (int i = Math.max(2, nda); i <= ndb; i++) {
            k += solve(pairs, a, b, i);
        }
        return k;
    }

    private static int solve(Set<Long> pairs, int a, int b, int nd) {
        int k = 0;
        for (int i = 1; i <= nd / 2; i++)
            k += solve(pairs, a, b, nd, i);
        return k;
    }

    private static int solve(Set<Long> pairs, int a, int b, int nd, int ndc) {
        int c10 = (int) Math.pow(10, ndc);

        int ndd = nd - ndc;
        int d10 = (int) Math.pow(10, ndd);

        int c0 = a / d10;
        int d0 = a / c10;

        int k = 0;
        for (int c = c0; c < c10; c++) {
            if (c * d10 > b)
                break;
            int d00 = d0;
            if (ndc == ndd)
                d00 = Math.max(d00, c + 1);
            for (int d = d00; d < d10; d++) {
                if (d * c10 > b)
                    break;
                int x = c * d10 + d;
                int y = d * c10 + c;
                if (x != y && x >= a && x <= b && y >= a && y <= b) {
                    long xx = Math.min(x, y);
                    long yy = Math.max(x, y);
                    long pair = xx * c10 * d10 + yy;
                    if (!pairs.contains(pair)) {
                        k++;
                        pairs.add(pair);
//                        System.out.printf("%d %d%n", Math.min(x, y), Math.max(x, y));
                    }
                }
            }
        }
        return k;
    }

}
