import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Q3M {
	public static void main(String[] args) throws Exception {
		compute();
	}

	private static void compute() throws Exception {
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"C:\\work\\Q3\\C-small-attempt0.in")));
		String line = null;
		int i = Integer.parseInt(br.readLine());
		List l = new ArrayList();
		for (int j = 0; j < i; j++) {
			line = br.readLine();
			String[] nums = line.split(" ");
			l.add(calculate(nums));
		}
		writeOutput(l);
	}

	private static int calculate(String[] nums) {
		int min = Integer.parseInt(nums[0]);
		int max = Integer.parseInt(nums[1]);
		int count = 0;
		List l = new ArrayList();
		for (int i = min; i <= max; i++) {
			for (int times = 1; times < countDigits(i); times++) {
				int res = shiftNum(i, times);
				if (res <= max && i < res) {
					if ((!l.contains((i + ":" + res)))) {
						l.add(i + ":" + res);
						l.add(res + ":" + i);
						count++;
					}
				}
			}
		}
		return count;
	}

	private static boolean checkZeros(int temp, int res) {
		if (temp % 10 == 0 || res % 10 == 0)
			return false;
		return true;
	}

	private static int shiftNum(int n, int times) {
		int base = (int) Math.pow(10, times);
		int temp2 = n / base;
		int placeHolder = (int) Math.pow((double) 10,
				(double) countDigits(temp2));
		int res = placeHolder * (n % base) + temp2;
		if (countDigits(res) == countDigits(n)) {
			return res;
		} else {
			return 2000001;
		}
	}

	public static int countDigits(int x) {
		if (x < 10)
			return 1;
		else {
			return 1 + countDigits(x / 10);
		}
	}

	private static void writeOutput(List l) throws Exception {
		StringBuffer b = new StringBuffer();
		int i = 1;
		BufferedWriter br = new BufferedWriter(new FileWriter(new File(
				"C:\\work\\Q3\\ans.txt")));
		for (Iterator iterator = l.iterator(); iterator.hasNext();) {
			br.write("Case #" + i++ + ": " + iterator.next());
			br.newLine();
		}
		br.close();
	}

}
package c;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import b.Dancing;

public class Recycled {
	public static void main(String[] args) throws IOException {
//		System.out.println(new Recycled().solve(1111, 2222));
		BufferedReader br = new BufferedReader(new FileReader("src/c/C-small-attempt0.in"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("src/c/out"));
		
		int row = Integer.parseInt(br.readLine());
		System.out.println("ROW : " + row);
		
		Recycled rec = new Recycled();
		
		for(int i=0; i<row; i++) {
			String[] line = br.readLine().split(" ");
			
			String res = "Case #" + (i+1) + ": " + rec.solve(Integer.parseInt(line[0]), Integer.parseInt(line[1]));
			bw.write(res + "\n");
			System.out.println(res);
		}
		
		bw.close();
		br.close();
	}

	public int solve(int a, int b) {
		int cnt = 0;
		for(int i=a; i<=b; i++) {
			for(int j=i; j<=b; j++) {
				if (recycled(i,j)) cnt++;
			}
		}
		return cnt;
	}

	private boolean recycled(int in, int im) {
		if (im<10 || in<10 || im == in) return false;
		
		String n = String.valueOf(in);
		String m = String.valueOf(im); 
		
		if (n.length() < m.length()) {
			n = "00000000000".substring(0, m.length() - n.length()) + n;
		}

		if (checkDigits(n, m)) {
//			System.out.print(n + "\t" + m + "\t");
			if (checkRotate(n, m)) {
//				System.out.println(n + "\t" + m);
//				System.out.println("X");
				return true;
			}
			else {
//				System.out.println();
				return false;
			}
		}
		
		return false;
	}
	
	private boolean checkRotate(String n, String m) {
		int len = n.length();
		for(int i=len-1; i>0; i--) {
			boolean correct = true;
			for(int j=0;j<len;j++) {
				int ni = (i+j >= len) ? (i+j-len) : i+j;
//				System.out.print("\n- " + ni + " " + j);
				if (n.charAt(ni) != m.charAt(j)) {
					correct = false;
					break;
				}
			}
			if (correct == true) return true;
		}
		return false;
	}

	int d[] = new int[10];
	
	private boolean checkDigits(String n, String m) {
		clearD();
		
		for(int i=0; i<n.length(); i++) {
			d[n.charAt(i)-'0']++;
			d[m.charAt(i)-'0']--;
		}
		
		for(int i=0; i<10; i++) {
			if (d[i] != 0) return false;
		}
		
		return true;
	}

	private void clearD() {
		for(int i=0; i<10; i++) {
			d[i] = 0;
		}
	}
}
