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();
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gcjqual;

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author greg
 */
public class GCJQual3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        GCJQual3 g = new GCJQual3();
        g.run();
    }

    private void run() {
        BufferedReader br = null;
        BufferedWriter bw = null;
        String eachLine;
        int count = 1;
        try {
            br = new BufferedReader(new FileReader("input3.txt"));
//            bw = new BufferedWriter(new OutputStreamWriter(System.out));
            bw = new BufferedWriter(new FileWriter("output3.txt"));
            String numTests = br.readLine();
            System.out.println(numTests);
            while ((eachLine = br.readLine()) != null) {
                bw.write("Case #" + count + ": ");
                bw.write(solve(eachLine));
                bw.newLine();
                count++;
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            Logger.getLogger(GCJQual3.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                bw.close();
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(GCJQual3.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

    private String solve(String eachLine) {
        String[] params = eachLine.split(" ");
        int A = Integer.valueOf(params[0]);
        int B = Integer.valueOf(params[1]);
        int recycledCount = 0;
        
        for (int n=A; n<=B; n++) {
            Set<Integer> possible = getRecycled(n);
            for (int m:possible) {
                if (m <= B) {
                    recycledCount++;
                }
            }
        }
        return "" + recycledCount;
    }

    private Set<Integer> getRecycled(int n) {
        Set<Integer> possible = new HashSet<Integer> ();
        int shift = 2;
        if ( n > 11 ) { // no single or 10 or 11
            if ( n >= 1000000) {
                shift = 7;
            } else if ( n >= 100000) {
                shift = 6;
            } else if ( n >= 10000) {
                shift = 5;
            } else if ( n >= 1000) {
                shift = 4;
            } else if ( n >= 100 ) {
                shift = 3;
            }
            int newNum = n;
            for ( int i =0; i< shift-1; i++) {
                int last = newNum % 10;
                newNum = (int) (newNum / 10 + (Math.pow(10, shift-1)*last));
                if ( newNum > n ) {
                    possible.add(newNum);
                }
            }
        }
        // Cache possible
        return possible;
    }
    
}

