/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumbers;

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

package qual;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class C {
	
	private Scanner scanner;

	private void solve() throws FileNotFoundException {
		File input = new File("data\\qual\\C-small-attempt0.in");
		scanner = new Scanner(input);

		File test = new File("data\\qual\\C.out");
		PrintStream out = new PrintStream(new FileOutputStream(test));
		System.setOut(out);

		int testCase = scanner.nextInt();
		scanner.nextLine();

		for (int i = 1; i <= testCase; i++) {
			System.out.printf("Case #%d: ", i);
			solveCase();
		}

	}

	private void solveCase() {
		int[] p10 = {
				1,
				10,
				100,
				1000,
				10000,
				100000,
				1000000,
				10000000,
				100000000,
				1000000000
		};
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int len = (a + "").length();
		Set ans = new HashSet();
		for (int i = 1; i < len; i++) {
			for (int prefix = p10[i - 1]; prefix < p10[i]; prefix++) {
				for (int suffix = p10[len - i - 1]; suffix < p10[len - i]; suffix++) {
					int n = prefix * p10[len - i] + suffix;
					int m = suffix * p10[i] + prefix;
					if (a <= n && n < m && m <= b) {
//						System.out.println(prefix + "-" + suffix + " " + n + " " + m);
						ans.add(n + "#" + m);
					}
				}
			}
		}
		System.out.println(ans.size());
	}

	public static void main(String[] args) throws FileNotFoundException {
		new C().solve();
	}

}
