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 mairbek.codejam;

import com.google.common.collect.Lists;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class SolutionC {

    public static void main(String[] args) {


        List<Pair<Integer, Integer>> input = parseInputFile("50\n" +
                "146 982\n" +
                "10 11\n" +
                "733 764\n" +
                "144 975\n" +
                "112 999\n" +
                "109 939\n" +
                "166 931\n" +
                "101 984\n" +
                "113 949\n" +
                "100 999\n" +
                "176 968\n" +
                "186 186\n" +
                "122 985\n" +
                "156 929\n" +
                "17 35\n" +
                "953 953\n" +
                "117 952\n" +
                "158 982\n" +
                "150 993\n" +
                "140 959\n" +
                "119 945\n" +
                "149 993\n" +
                "131 970\n" +
                "153 955\n" +
                "969 976\n" +
                "185 911\n" +
                "143 960\n" +
                "141 957\n" +
                "136 933\n" +
                "170 925\n" +
                "113 979\n" +
                "100 100\n" +
                "2 4\n" +
                "178 999\n" +
                "109 915\n" +
                "110 980\n" +
                "100 999\n" +
                "151 960\n" +
                "150 992\n" +
                "117 932\n" +
                "129 936\n" +
                "180 978\n" +
                "128 937\n" +
                "185 939\n" +
                "190 933\n" +
                "25 56\n" +
                "128 971\n" +
                "202 316\n" +
                "105 970\n" +
                "167 923\n");

        System.out.println(input);

        int i = 1;
        for (Pair<Integer, Integer> range : input) {
            System.out.println("Case #" + i + ": " + findRecycled(range).size());
            i++;
        }


    }


    private static List<Pair<Integer, Integer>> parseInputFile(String content) {
        String[] split = content.split("\n");

        int num = Integer.parseInt(split[0]);
        List<Pair<Integer, Integer>> result = Lists.newArrayList();

        for (int i = 1; i <= num; i++) {
            String[] pairSplit = split[i].split(" ");
            result.add(Pair.create(Integer.parseInt(pairSplit[0]), Integer.parseInt(pairSplit[1])));
        }

        return result;
    }



    private static Set<Pair<Integer, Integer>> findRecycled(Pair<Integer, Integer> range) {
        return findRecycled(range.getFirst(), range.getSecond());
    }

    private static Set<Pair<Integer, Integer>> findRecycled(int from, int to) {
        Set<Pair<Integer, Integer>> result = new LinkedHashSet<Pair<Integer, Integer>>();

        for (int i = from; i <= to; i++) {
            for (int j = from; j <= to; j++) {
                if (i == j) {
                    continue;
                }

                int first = i;
                int second = j;

                if (first < second) {
                    second = i;
                    first = j;
                }

                if (areEqualRecycled(first, second)) {
                    result.add(Pair.create(first, second));
                }
            }
        }


        return result;
    }


    private static boolean areEqualRecycled(int one, int two) {
        String oneS = String.valueOf(one);
        String twoS = String.valueOf(two);

        return (twoS + twoS).contains(oneS);

    }
}
