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

package Happy;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays.*;
import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.StringTokenizer;

/**
 *
 * @author ipoqi
 */
public class Happy {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Happy().haha();
    }

    public void haha() {
        BufferedReader in = null;
        BufferedWriter out = null;
        try{
            in = new BufferedReader(new FileReader("C-large.in"));
            out = new BufferedWriter(new FileWriter("LLL.out"));
            int T = Integer.parseInt(in.readLine());
            System.out.println("T="+T);

            //LinkedList<Integer> mm = new LinkedList<Integer>();
            //mm.add(new LinkedList<Integer>());
           //int[][] mm;
           //for(int ii=0;ii<mm.length;ii++){
           //     mm[0][ii] = 1;
           //}


            for(int i=0;i<T;i++){
                String[] line = in.readLine().split(" ");
                int A = Integer.parseInt(line[0]);
                int B = Integer.parseInt(line[1]);
                //System.out.print(" A = "+A+"\n");
                //System.out.print(" B = "+B+"\n");

                int ans = 0;

                
                for(int j=A;j<B;j++){
                    int n=j;
                    if(n>=10){
                        String N = Integer.toString(n);
                        int nlen = N.length();
                        List<Integer> oks = new ArrayList<Integer>();
                        for(int k=0;k<nlen-1;k++){
                            String M = "";
                            for(int kk=1;kk<=nlen;kk++){
                                 M = M + N.charAt((k+kk)%nlen);
                            }
                            int m = Integer.parseInt(M);
                            //System.out.print(" N = "+N+"\n");
                            //System.out.print(" M = "+M+"\n");

                            if(m>n && m<=B) {
                                boolean isNewOne = true;
                                for(int kkk=0;kkk<oks.size();kkk++){
                                    //System.out.print(" KKK = "+oks.get(kkk)+"\n");
                                    if(m==oks.get(kkk)){
                                        isNewOne = false;
                                    }
                                }
                                if(isNewOne){
                                    //System.out.print(" N = "+N+"\n");
                                    //System.out.print(" M = "+M+"\n");
                                    oks.add(m);
                                    ans++;
                                }
                            }
                        }
                    }
                }
                out.write("Case #"+(i+1)+": "+ans+"\n");
                System.out.print("Case #"+(i+1)+": "+ans+"\n");
            }
            in.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            try{
                in.close();
                out.close();
            }catch(Exception e1){
                e1.printStackTrace();
            }
        }
        System.out.print("YES!\n");
    }

}
package quialification;

import base.Base;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: babulya
 * Date: 14.04.12
 * Time: 19:45
 * To change this template use File | Settings | File Templates.
 */
public class C extends Base {
    private static class Number {
        private int[] digits;

        private Number(int[] digits) {
            this.digits = digits;
        }

        public Number(int N) {
            int dc = (int) Math.ceil(Math.log10(N + 1));
            digits = new int[dc];
            for (int i = 0; i < dc; i++) {
                digits[i] = N % 10;
                N = N / 10;
            }
        }

        private static int compareTo(int o1, int o2) {
            return o1 - o2;
        }

        public int compareTo(Number other) {
            int res = compareTo(digits.length, other.digits.length);
            if (res != 0) return res;
            int ind = digits.length - 1;
            while (ind >= 0 && digits[ind] == other.digits[ind]) {
                ind--;
            }
            if (ind >= 0) return compareTo(digits[ind], other.digits[ind]);
            return 0;
        }

        public Set<Number> pairs() {
            Set<Number> res = new HashSet<Number>();
            for (int i = 0; i < digits.length - 1; i++) {
                int[] newdigits = new int[digits.length];
                for (int j = 0; j <= i; j++) {
                    newdigits[j + digits.length - i - 1] = digits[j];
                }
                for (int j = i + 1; j < digits.length; j++) {
                    newdigits[j - i - 1] = digits[j];
                }
                res.add(new Number(newdigits));
            }
            return res;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Number number = (Number) o;

            if (!Arrays.equals(digits, number.digits)) return false;

            return true;
        }

        @Override
        public int hashCode() {
            return digits != null ? Arrays.hashCode(digits) : 0;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            for (int i = digits.length - 1; i >= 0; i--) {
                sb.append(digits[i]);
            }
            return sb.toString();
        }
    }

    private static int solve(int a, int b) {
        int result = 0;
        Number A = new Number(a);
        Number B = new Number(b);
        for (int n = a; n <= b; n++) {
            Number N = new Number(n);
            for (Number M : N.pairs()) {
                if (A.compareTo(N) <= 0 && N.compareTo(M) < 0 && M.compareTo(B) <= 0) {
                    result++;
                }
            }
        }
        return result;
    }

    @Override
    protected void solve(Scanner in, PrintStream out) {
        int T = in.nextInt();
        for (int i = 1; i <= T; i++) {
            int A = in.nextInt();
            int B = in.nextInt();
            out.println(String.format("Case #%d: %d", i, solve(A, B)));
        }
    }

    public static void main(String[] args) {
        long now = System.currentTimeMillis();
        new C();
        System.out.println((System.currentTimeMillis() - now)/1000);
    }
}
