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.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;

public class C {

	void start() {
		Scanner sc=new Scanner(System.in);
		int nt=sc.nextInt();
		for (int tc=1; tc<=nt; tc++) {
			int a=sc.nextInt(), b=sc.nextInt(), re=0;
			if (a<b && a>9) {
				int p=1;
				while (p*10<b) 
					p*=10;
				for (int x=a; x<=b; x++) {
					int z=x;
					do {
						z=z/10 + z%10*p;
						if (z>x && z>=a && z<=b) 
							re++;
					} while (z!=x);
				}
			}
			System.out.printf("Case #%d: %d\n", tc, re);
		}
	}

	public static void main(String[] args) throws Exception {
		new C().start();
	}
}