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.util.*;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cases = sc.nextInt();
		for(int ctr=0; ctr<cases; ctr++){
			int start = sc.nextInt();
			int end = sc.nextInt();
			HashSet<String> set = new HashSet<String>();
			for(int n=start; n<=end; n++){
				String s = Integer.toString(n);
				for(int i=1; i<s.length(); i++){
					String t = s.substring(i) + s.substring(0, i);
					int m = Integer.valueOf(t);
					if(t.replaceFirst("^0*", "").length() == s.length() && n != m && start <= m && m <= end){
						set.add(s+t);
					}
				}
			}
			System.out.printf("Case #%d: %d\n", ctr+1, set.size()/2);
		}
	}
}
