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.Scanner;
import java.io.File;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner s = new Scanner(new File("C-small-attempt0.in"));
        int test = Integer.parseInt(s.nextLine());
        for(int i=1; i<=test; i++){
            int a = s.nextInt();
            int b = s.nextInt();
            int pairs = 0;
            for(int n=a; n<b; n++){
                for(int m=n+1; m<=b; m++){
                    boolean rotation = isRotation(String.valueOf(n), String.valueOf(m));
                    if(rotation)
                        pairs++;
                }
            }
            System.out.println("Case #"+i+": "+pairs);
        }
    }
    
    static boolean isRotation(String s1,String s2) {
        return (s1.length() == s2.length()) && ((s1+s1).indexOf(s2) != -1);
    }
}
