import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class RecycledNumbers {
  
  public static void readInput(String pFileName, List<String> pInputCases) {
    File tFile = new File(pFileName);
    try {
      BufferedReader tBufferedReader = new BufferedReader(
          new InputStreamReader(new FileInputStream(tFile)), 4096);
      String tLineRead = tBufferedReader.readLine().trim();
      int tCaseSize = Integer.valueOf(tLineRead);
      int tLineIndex = 0;
      while(tLineIndex < tCaseSize) {
        tLineRead = tBufferedReader.readLine().trim();
        pInputCases.add(tLineRead);
        tLineIndex++;
      }
    } catch(FileNotFoundException pException) {
      pException.printStackTrace();
    } catch(IOException pException) {
      pException.printStackTrace();
    }
  }
  
  public static final int[] UNITS = { 1, 1, 10, 100, 1000, 10000, 100000, 1000000 };
  
  public static void main(String[] pArgs) {
    if(pArgs.length == 0) {
      System.out.println("no input");
      return;
    }
    List<String> tInputCases = new ArrayList<String>();
    
    readInput(pArgs[0], tInputCases);
    for(int tCaseIndex = 0; tCaseIndex < tInputCases.size(); tCaseIndex++) {
      String[] tInputs = tInputCases.get(tCaseIndex).split("[ ]+");
      int tLower = Integer.valueOf(tInputs[0]);
      int tUpper = Integer.valueOf(tInputs[1]);
      
      int tPairs = 0;
      Map<Long, Integer> tMapPairs = new HashMap<Long, Integer>();
      for(int tNumber = tLower; tNumber < tUpper; ++tNumber) {
        int tLength = String.valueOf(tNumber).length();
        int tValue = tNumber;
        List<Integer> tValues = new ArrayList<Integer>();
        tValues.add(tNumber);
        for(int i = 1; i < tLength; ++i) {
          int tHead = tValue / UNITS[tLength];
          int tTail = tValue - tHead * UNITS[tLength];
          int tNewValue = tTail * 10 + tHead;
          if((tLower <= tNewValue) && (tNewValue <= tUpper)) {
            tValues.add(tNewValue);
          }
          tValue = tNewValue;
        }
        if(tValues.size() > 1) {
          for(int i = 0; i < tValues.size() - 1; ++i) {
            for(int j = i + 1; j < tValues.size(); ++j) {
              int tOldValue = tValues.get(i);
              int tNewValue = tValues.get(j);
              long tKey = tOldValue * 10000000l + tNewValue;
              if((tOldValue < tNewValue) && (tOldValue != tNewValue)) {
                if(!tMapPairs.containsKey(tKey)) {
                  ++tPairs;
                  tMapPairs.put(tKey, 1);
                }
              }
            }
          }
        }
      }
      System.out.println("Case #" + (tCaseIndex + 1) + ": " + tPairs);
    }
  }
}
