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.bd.codejam.y2012;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class C {
	public void solve() throws IOException {
		Scanner in = new Scanner(new File(getClass().getSimpleName() + ".in.txt"));
		PrintWriter out = new PrintWriter(new File(getClass().getSimpleName() + ".out.txt"));

		int T = Integer.parseInt(in.nextLine());
		for (int t = 0; t < T; t++) {
			int A = in.nextInt();
			int B = in.nextInt();
			int result = solve(A, B);
			
			out.println("Case #" + (t + 1) + ": " + result);
			System.out.println("Case #" + (t + 1) + ": " + result);
		}

		in.close();
		out.close();
	}
	
	private int solve(int A, int B) {
		line = 1;
		int r = 0;
		for (int n = A; n < B; n++) {
			r += recycledPairs(n, B);
		}
		
		return r;
	}
	
	int line = 1;
	private int recycledPairs(int n, int max) {
		int r = 0;
		for (int pair : recycledPairs(n)) {
			if (n < pair && pair <= max) {
				r++;
				//System.out.println((line++) + ": " + n + " " + pair);
			}
		}
		return r;
		
		
	}
	
	private List<Integer> recycledPairs(int n) {
		String s = Integer.toString(n);
		
		List<Integer> r = new ArrayList<Integer>(s.length()-1);
		for (int i = 1; i < s.length(); i++) {
			String shift = shift(s, i);
			if (shift.charAt(0) != '0') {
				int shifti = Integer.parseInt(shift);
				if (!r.contains(shifti)) {
					r.add(shifti);
				}
			}
		}
		return r;
	}
	
	private String shift(String s, int n) {
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(((i+(s.length()-n))%s.length()));
		}
		
		return new String(c);
	}
	
	

	public static void main(String[] args) throws IOException {
		new C().solve();
	}
}