import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
package code;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class C {

	final static String CASE_NO = "Case #";
	final static String SUFFIX = ": ";

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		int total;
		int T; // nuber of test cases

		BufferedReader br = readFile("testC");

		T = Integer.parseInt(br.readLine());
		total = T;

		while (T > 0) {
			T--;
			int pairs = 0;
			String line = br.readLine();
			String[] input = line.split(" ");
			int i = 0;
			int A = Integer.parseInt(input[i++]);
			int B = Integer.parseInt(input[i++]);

			for (int x = A; x < B; x++) {
				int mulFact = getMulFactor(x);

				int num = getPrefix(x, mulFact) + getSuffix(x);

				while (num != x) {
					if (num > x && num <= B) {
						pairs++;

					}
					num = getPrefix(num, mulFact) + getSuffix(num);
				}
			}
			System.out.println(CASE_NO + (total - T) + SUFFIX + pairs);

		}

	}

	private static BufferedReader readFile(String fileName)
			throws FileNotFoundException {

		FileReader fr = new FileReader(fileName);
		BufferedReader br = new BufferedReader(fr);
		return br;
	}

	private static int getMulFactor(int num) {
		int m = 1;

		while ((num / m) > 9) {
			m = m * 10;
		}
		return m;
	}

	private static int getPrefix(int num, int mul) {
		int i = 10;
		int mod = num % i;
		while (mod == 0) {
			i = i * 10;
			mod = num % i;
			mul = mul / 10;
		}

		return mul * mod;
	}

	private static int getSuffix(int num) {
		int i = 1;
		int mod;

		do {
			i = i * 10;
			mod = num % i;
		} while (mod == 0);

		return num / i;
	}
}
