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 com.google.code;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;

/**
 * @author Wellington Tadeu dos Santos [wellsantos@wellsantos.com]
 */
public class ProblemC {

    boolean endOfLine;
    Reader reader;
    Appendable writer;

    public ProblemC(Reader in, Appendable out) throws Exception {
        this.reader = in;
        this.writer = out;
    }

    public static void main(String[] args) throws Exception {
        long time = System.nanoTime();
        String in = "./src/com/google/code/C-small-attempt0.in";
        String out = in.substring(0, in.length() - 3) + ".out";
        FileReader reader = new FileReader(in);
        FileWriter writer = new FileWriter(out);
        new ProblemC(reader, writer).run();
        writer.flush();
        writer.close();
        reader.close();
        System.out.println((System.nanoTime() - time) / 1000000.0);
    }

    private int readInt() throws Exception {
        int val = 0;
        int chr;
        while ((chr = this.reader.read()) >= '0' && chr <= '9') {
            val = val * 10 + (chr - '0');
        }
        switch (chr) {
            case '\r':
                chr = this.reader.read();
            case '\n':
            case -1:
                this.endOfLine = true;
                break;
            default:
                this.endOfLine = false;
        }
        return val;
    }

    private void run() throws Exception {
        int testCases = this.readInt();

        for (int caseIndex = 1; caseIndex <= testCases; caseIndex++) {
            int a = this.readInt();
            int b = this.readInt();
            int count = 0;
            for (int n = a; n <= b; n++) {
                for (int m = n + 1; m <= b; m++) {
                    String nx = String.valueOf(n);
                    String mx = String.valueOf(m);
                    int f = nx.length();
                    if (f == mx.length()) {
                        for (int i = 0; i < f; i++) {
                            if (mx.charAt(i) == nx.charAt(f - 1)) {
                                if (mx.substring(0, i + 1).equals(nx.substring(f - i - 1, f))
                                        && mx.substring(i + 1, f).equals(nx.substring(0, f - i - 1))) {
                                    count++;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            this.writer.append("Case #" + caseIndex + ": " + count + "\n");
        }
    }
}