import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class QrC {
	private CodeJamTextInputReader input = null;
	private CodeJamTextOutputWriter output = null;

	public static void main(String args[]) {
		// CodeJamUtils.initLineEndings();
		try {
			QrC qrA = new QrC();
			qrA.run(new File(args[0]), new File(args[1]));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidInputException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public QrC() {
	}

	public void run(File outputFile, File inputFile)
			throws InvalidInputException, IOException {
		try {
			input = new CodeJamTextInputReader(inputFile);
			output = new CodeJamTextOutputWriter(outputFile);

			actualRun();
		} finally {
			if (input != null) {
				input.close();
			}
			if (output != null) {
				output.close();
			}
		}
	}

	private void actualRun() throws IOException {
		while (input.hasNextTestCase()) {
			String in = input.readNextLine();
			final int textCaseNum = input.getLastReadTestCaseNumber();

			output.outputTestCase(textCaseNum, singleTestCase(in));
		}
	}

	private String singleTestCase(String in) {
		CodeJamLineParser parser = new CodeJamLineParser(in);
		final int lowerBound = parser.readNextInt();
		final int upperBound = parser.readNextInt();

		int numOfRecycled = 0;

		Set<RecycledPair> alreadyHit = new HashSet<RecycledPair>();

		RecycledPair comparePair = new RecycledPair();
		
		for (int i = lowerBound; i <= upperBound; ++i) {
			int leftMask = getHighestMask(i);
			int rightMask = 10;
			while (leftMask >= 10) {
				int recycled = buildRecycled(i, leftMask, rightMask);
				comparePair.set(i, recycled);
				if (recycled != i && recycled >= lowerBound
						&& recycled <= upperBound
						&& !alreadyHit.contains(comparePair)) {
					alreadyHit.add(new RecycledPair(comparePair));
					++numOfRecycled;
				}
				rightMask = rightMask * 10;
				leftMask = leftMask / 10;
			}
		}

		return Integer.toString(numOfRecycled);
	}

	int buildRecycled(int in, int leftMask, int rightMask) {
		int rightPart = in % rightMask;
		int leftPart = in / rightMask;

		return (rightPart * leftMask) + leftPart;
	}

	int getHighestMask(int in) {
		int mask = 10;
		while (in / mask != 0) {
			mask = mask * 10;
		}
		return mask / 10;
	}

	int getNumOfDigits(int in) {
		int numOfDigits = 1;
		int mask = 10;
		while (in / mask != 0) {
			++numOfDigits;
			mask = mask * 10;
		}
		return numOfDigits;
	}
}
