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 es.salamanca.google;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ãngel Alfonso GÃ³mez
 */
public class Recycled {
    public static void main(String[] args) {
        BufferedReader bf;
        FileReader fl;
        FileWriter f2;
        
        try {
            fl = new FileReader("C:\\C-small-attempt2.in");
            f2 = new FileWriter("C:\\C-small-attempt2.out");
            bf = new BufferedReader(fl);
            int num = Integer.parseInt(bf.readLine());
            System.out.println(num);
            for (int i = 0; i < num; i++) {
                int cont=0;
                f2.append("Case #"+(i+1)+": ");
                System.out.print("Case #"+(i+1)+": ");
                String linea = bf.readLine();
                int num1 = Integer.parseInt(linea.substring(0, linea.indexOf(" ")));
                int num2 = Integer.parseInt(linea.substring(linea.indexOf(" ")+1));
                for (int j=num1;j<num2;j++) {
                    for(int k=j+1;k<(num2+1);k++)
                       if (Recycled(j,k)) cont++;
                }
                
                f2.append(Integer.toString(cont));
                f2.append("\r\n");
                System.out.println(cont);
            }
            f2.close();
            fl.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Speaking.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IOException ex) {
            Logger.getLogger(Speaking.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    public static Boolean Recycled(int n,int m) {
        String num1 = Integer.toString(n);
        String num2 = Integer.toString(m);
        for (int i=0;i<(num1.length()-1);i++) {
            String sub = num1.substring(i+1).concat(num1.substring(0, i+1));
            if (sub.equals(num2)) {
                return true;
            }
        }
        return false;
    }
}
