
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

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

package googlecodejam;

/**
 *
 * @author Bhanu
 */

import java.util.*;

public class RecycleNumbers {

public static void main(String arg[]) throws Exception
{
    ArrayList st = new ArrayList();
    ArrayList st1 = new ArrayList();
    //java.io.PrintWriter pt = new java.io.PrintWriter(new java.io.File("D:\\map.txt"));
    int two[] = {12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67, 68, 69, 78, 79, 89};
   int two1[] = {21, 31, 41, 51, 61, 71, 81, 91, 32, 42, 52, 62, 72, 82, 92, 43, 53, 63, 73, 83, 93, 54, 64, 74, 84, 94, 65, 75, 85, 95, 76, 86, 96, 87, 97, 98};
    int count = 0;

    int three[] = {101, 102, 103, 104, 105, 106, 107, 108, 109, 112, 112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119, 119, 120, 121, 122, 122, 123, 123, 124, 124, 125, 125, 126, 126, 127, 127, 128, 128, 129, 129, 130, 131, 132, 132, 133, 133, 134, 134, 135, 135, 136, 136, 137, 137, 138, 138, 139, 139, 140, 141, 142, 142, 143, 143, 144, 144, 145, 145, 146, 146, 147, 147, 148, 148, 149, 149, 150, 151, 152, 152, 153, 153, 154, 154, 155, 155, 156, 156, 157, 157, 158, 158, 159, 159, 160, 161, 162, 162, 163, 163, 164, 164, 165, 165, 166, 166, 167, 167, 168, 168, 169, 169, 170, 171, 172, 172, 173, 173, 174, 174, 175, 175, 176, 176, 177, 177, 178, 178, 179, 179, 180, 181, 182, 182, 183, 183, 184, 184, 185, 185, 186, 186, 187, 187, 188, 188, 189, 189, 190, 191, 192, 192, 193, 193, 194, 194, 195, 195, 196, 196, 197, 197, 198, 198, 199, 199, 202, 203, 204, 205, 206, 207, 208, 209, 212, 213, 214, 215, 216, 217, 218, 219, 223, 223, 224, 224, 225, 225, 226, 226, 227, 227, 228, 228, 229, 229, 230, 231, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239, 239, 240, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 250, 251, 252, 253, 253, 254, 254, 255, 255, 256, 256, 257, 257, 258, 258, 259, 259, 260, 261, 262, 263, 263, 264, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 270, 271, 272, 273, 273, 274, 274, 275, 275, 276, 276, 277, 277, 278, 278, 279, 279, 280, 281, 282, 283, 283, 284, 284, 285, 285, 286, 286, 287, 287, 288, 288, 289, 289, 290, 291, 292, 293, 293, 294, 294, 295, 295, 296, 296, 297, 297, 298, 298, 299, 299, 303, 304, 305, 306, 307, 308, 309, 313, 314, 315, 316, 317, 318, 319, 323, 324, 325, 326, 327, 328, 329, 334, 334, 335, 335, 336, 336, 337, 337, 338, 338, 339, 339, 340, 341, 342, 343, 344, 344, 345, 345, 346, 346, 347, 347, 348, 348, 349, 349, 350, 351, 352, 353, 354, 354, 355, 355, 356, 356, 357, 357, 358, 358, 359, 359, 360, 361, 362, 363, 364, 364, 365, 365, 366, 366, 367, 367, 368, 368, 369, 369, 370, 371, 372, 373, 374, 374, 375, 375, 376, 376, 377, 377, 378, 378, 379, 379, 380, 381, 382, 383, 384, 384, 385, 385, 386, 386, 387, 387, 388, 388, 389, 389, 390, 391, 392, 393, 394, 394, 395, 395, 396, 396, 397, 397, 398, 398, 399, 399, 404, 405, 406, 407, 408, 409, 414, 415, 416, 417, 418, 419, 424, 425, 426, 427, 428, 429, 434, 435, 436, 437, 438, 439, 445, 445, 446, 446, 447, 447, 448, 448, 449, 449, 450, 451, 452, 453, 454, 455, 455, 456, 456, 457, 457, 458, 458, 459, 459, 460, 461, 462, 463, 464, 465, 465, 466, 466, 467, 467, 468, 468, 469, 469, 470, 471, 472, 473, 474, 475, 475, 476, 476, 477, 477, 478, 478, 479, 479, 480, 481, 482, 483, 484, 485, 485, 486, 486, 487, 487, 488, 488, 489, 489, 490, 491, 492, 493, 494, 495, 495, 496, 496, 497, 497, 498, 498, 499, 499, 505, 506, 507, 508, 509, 515, 516, 517, 518, 519, 525, 526, 527, 528, 529, 535, 536, 537, 538, 539, 545, 546, 547, 548, 549, 556, 556, 557, 557, 558, 558, 559, 559, 560, 561, 562, 563, 564, 565, 566, 566, 567, 567, 568, 568, 569, 569, 570, 571, 572, 573, 574, 575, 576, 576, 577, 577, 578, 578, 579, 579, 580, 581, 582, 583, 584, 585, 586, 586, 587, 587, 588, 588, 589, 589, 590, 591, 592, 593, 594, 595, 596, 596, 597, 597, 598, 598, 599, 599, 606, 607, 608, 609, 616, 617, 618, 619, 626, 627, 628, 629, 636, 637, 638, 639, 646, 647, 648, 649, 656, 657, 658, 659, 667, 667, 668, 668, 669, 669, 670, 671, 672, 673, 674, 675, 676, 677, 677, 678, 678, 679, 679, 680, 681, 682, 683, 684, 685, 686, 687, 687, 688, 688, 689, 689, 690, 691, 692, 693, 694, 695, 696, 697, 697, 698, 698, 699, 699, 707, 708, 709, 717, 718, 719, 727, 728, 729, 737, 738, 739, 747, 748, 749, 757, 758, 759, 767, 768, 769, 778, 778, 779, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 788, 789, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 798, 799, 799, 808, 809, 818, 819, 828, 829, 838, 839, 848, 849, 858, 859, 868, 869, 878, 879, 889, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 899, 909, 919, 929, 939, 949, 959, 969, 979, 989};
    int three1[]= {110, 210, 310, 410, 510, 610, 710, 810, 910, 211, 121, 311, 131, 411, 141, 511, 151, 611, 161, 711, 171, 811, 181, 911, 191, 201, 211, 212, 221, 312, 231, 412, 241, 512, 251, 612, 261, 712, 271, 812, 281, 912, 291, 301, 311, 213, 321, 313, 331, 413, 341, 513, 351, 613, 361, 713, 371, 813, 381, 913, 391, 401, 411, 214, 421, 314, 431, 414, 441, 514, 451, 614, 461, 714, 471, 814, 481, 914, 491, 501, 511, 215, 521, 315, 531, 415, 541, 515, 551, 615, 561, 715, 571, 815, 581, 915, 591, 601, 611, 216, 621, 316, 631, 416, 641, 516, 651, 616, 661, 716, 671, 816, 681, 916, 691, 701, 711, 217, 721, 317, 731, 417, 741, 517, 751, 617, 761, 717, 771, 817, 781, 917, 791, 801, 811, 218, 821, 318, 831, 418, 841, 518, 851, 618, 861, 718, 871, 818, 881, 918, 891, 901, 911, 219, 921, 319, 931, 419, 941, 519, 951, 619, 961, 719, 971, 819, 981, 919, 991, 220, 320, 420, 520, 620, 720, 820, 920, 221, 321, 421, 521, 621, 721, 821, 921, 322, 232, 422, 242, 522, 252, 622, 262, 722, 272, 822, 282, 922, 292, 302, 312, 322, 323, 332, 423, 342, 523, 352, 623, 362, 723, 372, 823, 382, 923, 392, 402, 412, 422, 324, 432, 424, 442, 524, 452, 624, 462, 724, 472, 824, 482, 924, 492, 502, 512, 522, 325, 532, 425, 542, 525, 552, 625, 562, 725, 572, 825, 582, 925, 592, 602, 612, 622, 326, 632, 426, 642, 526, 652, 626, 662, 726, 672, 826, 682, 926, 692, 702, 712, 722, 327, 732, 427, 742, 527, 752, 627, 762, 727, 772, 827, 782, 927, 792, 802, 812, 822, 328, 832, 428, 842, 528, 852, 628, 862, 728, 872, 828, 882, 928, 892, 902, 912, 922, 329, 932, 429, 942, 529, 952, 629, 962, 729, 972, 829, 982, 929, 992, 330, 430, 530, 630, 730, 830, 930, 331, 431, 531, 631, 731, 831, 931, 332, 432, 532, 632, 732, 832, 932, 433, 343, 533, 353, 633, 363, 733, 373, 833, 383, 933, 393, 403, 413, 423, 433, 434, 443, 534, 453, 634, 463, 734, 473, 834, 483, 934, 493, 503, 513, 523, 533, 435, 543, 535, 553, 635, 563, 735, 573, 835, 583, 935, 593, 603, 613, 623, 633, 436, 643, 536, 653, 636, 663, 736, 673, 836, 683, 936, 693, 703, 713, 723, 733, 437, 743, 537, 753, 637, 763, 737, 773, 837, 783, 937, 793, 803, 813, 823, 833, 438, 843, 538, 853, 638, 863, 738, 873, 838, 883, 938, 893, 903, 913, 923, 933, 439, 943, 539, 953, 639, 963, 739, 973, 839, 983, 939, 993, 440, 540, 640, 740, 840, 940, 441, 541, 641, 741, 841, 941, 442, 542, 642, 742, 842, 942, 443, 543, 643, 743, 843, 943, 544, 454, 644, 464, 744, 474, 844, 484, 944, 494, 504, 514, 524, 534, 544, 545, 554, 645, 564, 745, 574, 845, 584, 945, 594, 604, 614, 624, 634, 644, 546, 654, 646, 664, 746, 674, 846, 684, 946, 694, 704, 714, 724, 734, 744, 547, 754, 647, 764, 747, 774, 847, 784, 947, 794, 804, 814, 824, 834, 844, 548, 854, 648, 864, 748, 874, 848, 884, 948, 894, 904, 914, 924, 934, 944, 549, 954, 649, 964, 749, 974, 849, 984, 949, 994, 550, 650, 750, 850, 950, 551, 651, 751, 851, 951, 552, 652, 752, 852, 952, 553, 653, 753, 853, 953, 554, 654, 754, 854, 954, 655, 565, 755, 575, 855, 585, 955, 595, 605, 615, 625, 635, 645, 655, 656, 665, 756, 675, 856, 685, 956, 695, 705, 715, 725, 735, 745, 755, 657, 765, 757, 775, 857, 785, 957, 795, 805, 815, 825, 835, 845, 855, 658, 865, 758, 875, 858, 885, 958, 895, 905, 915, 925, 935, 945, 955, 659, 965, 759, 975, 859, 985, 959, 995, 660, 760, 860, 960, 661, 761, 861, 961, 662, 762, 862, 962, 663, 763, 863, 963, 664, 764, 864, 964, 665, 765, 865, 965, 766, 676, 866, 686, 966, 696, 706, 716, 726, 736, 746, 756, 766, 767, 776, 867, 786, 967, 796, 806, 816, 826, 836, 846, 856, 866, 768, 876, 868, 886, 968, 896, 906, 916, 926, 936, 946, 956, 966, 769, 976, 869, 986, 969, 996, 770, 870, 970, 771, 871, 971, 772, 872, 972, 773, 873, 973, 774, 874, 974, 775, 875, 975, 776, 876, 976, 877, 787, 977, 797, 807, 817, 827, 837, 847, 857, 867, 877, 878, 887, 978, 897, 907, 917, 927, 937, 947, 957, 967, 977, 879, 987, 979, 997, 880, 980, 881, 981, 882, 982, 883, 983, 884, 984, 885, 985, 886, 986, 887, 987, 988, 898, 908, 918, 928, 938, 948, 958, 968, 978, 988, 989, 998, 990, 991, 992, 993, 994, 995, 996, 997, 998};

    //System.out.println(Arrays.binarySearch(two, 19));
    java.io.BufferedReader bin = new java.io.BufferedReader(new java.io.InputStreamReader (System.in));
  int T = Integer.parseInt( bin.readLine() );
  for(int i = 1; i <= T ; i++)
  {
            count = 0;
            String[] split = bin.readLine().split(" ");
            int a = Integer.parseInt(split[0]);
            int b = Integer.parseInt(split[1]);
            if( a >= 0 && a <= 9)
            {
                System.out.println("Case #" + i + ": " + 0);
            }
            else if(a >= 10 && a <= 99)
            {
                int b1 = Arrays.binarySearch(two, a);
                if(b1 < 0){b1 = b1 + 1; b1 = - b1;}

                int b2 = Arrays.binarySearch(two, b);
                if(b2 < 0){b2 = b2 + 1; b2 = - b2; b2 = b2 - 1;}

                for(;b1 <= b2; b1++)
                {
                       if(two1[b1] >= a && two1[b1] <= b) count++;
                }

                System.out.println("Case #" + i + ": " + count);

            }
            else  if(a >= 100 && a <= 999)
            {
                 int b1 = Arrays.binarySearch(three, a);
                if(b1 < 0){b1 = b1 + 1; b1 = - b1;}
                else{

                     while(b1 >= 0 && three[b1] == a) b1--;
                      b1 = b1 + 1;

                }


                int b2 = Arrays.binarySearch(three, b);
                if(b2 < 0){b2 = b2 + 1; b2 = - b2; b2 = b2 - 1;}
                else{
                     while(b2 <= three.length - 1 && three[b2] == b) b2++;
                      b2 = b2 - 1;

                }
               // System.out.println("B1 and B2" + b1 + " " + b2);
                for(;b1 <= b2; b1++)
                {
                       if(three1[b1] >= a && three1[b1] <= b) count++;
                }

                System.out.println("Case #" + i + ": " + count);


            }
            else                 System.out.println("Case #" + i + ": " + 0);





  }

  /*  for(int i = 100; i <= 999; i++)
    {

        int rem = i % 10;
        int q = i / 10;
        int temp = rem * 100 + q;
        if(temp > i){
            st.add(i);
            st1.add(temp);
        }

        rem = i % 100;
        q = i / 100;
        temp = rem * 10 + q;
        if(temp > i){
            st.add(i);
            st1.add(temp);
        }

    }

    pt.println(st1);
    pt.close(); */

}

}
