package com.menzus.gcj._2012.qualification.c;

import com.menzus.gcj.common.InputBlockParser;
import com.menzus.gcj.common.OutputProducer;
import com.menzus.gcj.common.impl.AbstractProcessorFactory;

public class CProcessorFactory extends AbstractProcessorFactory<CInput, COutputEntry> {
    public CProcessorFactory(String inputFileName) {
	super(inputFileName);
    }

    @Override
    protected InputBlockParser<CInput> createInputBlockParser() {
	return new CInputBlockParser();
    }

    @Override
    protected OutputProducer<CInput, COutputEntry> createOutputProducer() {
	return new COutputProducer();
    }
}

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


public class C_Qual {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for (int tt = 1; tt <= T; tt++) {
			int a=in.nextInt(),b=in.nextInt();
			int res=0;
			for(int i=a;i<=b;i++){
				String num = i+"";
				HashSet<Integer> vis=new HashSet<Integer>();
				for(int j=0;j<num.length();j++){
					String newNum = num.substring(j)+num.substring(0,j);
					int n = new Integer(newNum);
					if(i<n&&n>=a&&n<=b){
						if(vis.contains(n)){
							continue;
						}
						vis.add(n);
						res++;
					}
				}
			}
			System.out.printf("Case #%d: %d\n", tt,res);
		}
	}
	}