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;

class Main{
	public static void main(String[] args){
		Scanner S= new Scanner(System.in);
		int T=S.nextInt(), i, j, a, b;
		int val,n,n2,size;
		String aux;
		for(i=0;i<T;i++){
			a=S.nextInt();
			b=S.nextInt();
			val=0;
			if(b>=12){
				for(n=a>12?a:12;n<=b;n++){
					aux= ""+n;
					size=aux.length();
					for(j=1;j<size;j++){
						if(aux.charAt(0)<=aux.charAt(j)){
							n2= Integer.parseInt(aux.substring(j)+aux.substring(0,j));
							if(n2<=b && n2>n) val++;
						}
					}
				}
			}
			System.out.println("Case #" + (i+1) + ": " + val);
		}
	}
}