import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

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


public class probC {
	public static void main (String args[]) throws IOException
	{
		BufferedReader in = new BufferedReader(new FileReader("C:\\downloads\\c-small-attempt0.in"));
		BufferedWriter out = new BufferedWriter(new FileWriter("C:\\downloads\\c-small-output.in"));
		int t = Integer.parseInt(in.readLine());
		int i,j,k,l;
		int A,B;
		int len;
		int count;
	    for (i=1;i<=t;i++)
		{ StringTokenizer st = new StringTokenizer(in.readLine());
		  A = Integer.parseInt(st.nextToken());
		  B = Integer.parseInt(st.nextToken());
		  count=0;
		  len = String.valueOf(A).length();
		  int[] temp =  new int[len];
		  for (j=A;j<=B;j++)
		  { String n;
		    n = String.valueOf(j);
		    
		    for (k=0;k<len-1;k++)
		    { int flag=0;
		      temp[k] = Integer.parseInt(n);
		      StringBuilder sb = new StringBuilder();
		    	for (l=1;l<len;l++)		         
		          sb.append(n.charAt(l));
		    	sb.append(n.charAt(0));
		    	int y = Integer.parseInt(sb.toString());
		    	for (int x : temp)
		    		if (x==y)
		    		{ flag=1;
		    		  break;
		    		}
		    	if ((flag==0) && (y>j) && (y<=B))
		    			count++;
		    	n = sb.toString();
		  }
		    }
		out.write("Case #"+i+": "+count);
		out.newLine();
		  
		}
		  out.close();
	}

}
