import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Q3M {
	public static void main(String[] args) throws Exception {
		compute();
	}

	private static void compute() throws Exception {
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"C:\\work\\Q3\\C-small-attempt0.in")));
		String line = null;
		int i = Integer.parseInt(br.readLine());
		List l = new ArrayList();
		for (int j = 0; j < i; j++) {
			line = br.readLine();
			String[] nums = line.split(" ");
			l.add(calculate(nums));
		}
		writeOutput(l);
	}

	private static int calculate(String[] nums) {
		int min = Integer.parseInt(nums[0]);
		int max = Integer.parseInt(nums[1]);
		int count = 0;
		List l = new ArrayList();
		for (int i = min; i <= max; i++) {
			for (int times = 1; times < countDigits(i); times++) {
				int res = shiftNum(i, times);
				if (res <= max && i < res) {
					if ((!l.contains((i + ":" + res)))) {
						l.add(i + ":" + res);
						l.add(res + ":" + i);
						count++;
					}
				}
			}
		}
		return count;
	}

	private static boolean checkZeros(int temp, int res) {
		if (temp % 10 == 0 || res % 10 == 0)
			return false;
		return true;
	}

	private static int shiftNum(int n, int times) {
		int base = (int) Math.pow(10, times);
		int temp2 = n / base;
		int placeHolder = (int) Math.pow((double) 10,
				(double) countDigits(temp2));
		int res = placeHolder * (n % base) + temp2;
		if (countDigits(res) == countDigits(n)) {
			return res;
		} else {
			return 2000001;
		}
	}

	public static int countDigits(int x) {
		if (x < 10)
			return 1;
		else {
			return 1 + countDigits(x / 10);
		}
	}

	private static void writeOutput(List l) throws Exception {
		StringBuffer b = new StringBuffer();
		int i = 1;
		BufferedWriter br = new BufferedWriter(new FileWriter(new File(
				"C:\\work\\Q3\\ans.txt")));
		for (Iterator iterator = l.iterator(); iterator.hasNext();) {
			br.write("Case #" + i++ + ": " + iterator.next());
			br.newLine();
		}
		br.close();
	}

}
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;


public class numberproblem
{	public static void main(String args[])
	{
	
	
	 try
	  {
	  FileInputStream in = new FileInputStream("/Users/nanz/Downloads/C-small-attempt0.in");
	  BufferedReader br = new BufferedReader(new InputStreamReader(in));
	  String strLine;
	  int line=0;
	  int ln;
	  while((strLine = br.readLine())!= null)
	  {
	   if(line==0)
		   {
		   		ln = Integer.parseInt(strLine);
		   }
	   else
	   
	   	   {
		        //System.out.println(strLine);
		   
		   		String nums[]=strLine.split(" ");
		   		//System.out.println(nums);
		   		int num_A= Integer.parseInt(nums[0]);
		   		int num_B= Integer.parseInt(nums[1]);
		   		RotateNumber(num_A,num_B,line);

			   
		   }
	    line++;

	   }
	   
	   }
	catch(Exception e){
		   System.out.println(e);
		  }
		  	 
    
}

private static void RotateNumber(int A, int B, int line)
{
      int num = A;
      double pairs_2=0;
      double pairs_3=0;
      double pairs;
      while(num<=B)
      {
      int numdigits = (int) Math.log10((double)num)+1; // would return numdigits - 1
      int ones, tens, hundrds;
      
      if(numdigits==2)
      {
    	  //System.out.println("2 digit number");
    	  ones = num%10;
    	  int temp=num/10;
    	  tens=temp%10;
    	  //System.out.println(ones+" "+tens);
    	  if((tens!=ones)&&(tens!=0)&&(ones!=0))
    	  {
    		  int num_pair = ones*10+tens;
    		  if((num_pair>=A)&&(num_pair<=B))
    		  {
    			  pairs_2=pairs_2+1;
    			  //System.out.println(num_pair);
    		  }
    		  
    	  }

    		 
      }
      else if(numdigits==3)
      {
    	  int pair_a, pair_b, pair_c;
    	  //System.out.println("3 digit number !");
    	  ones = num%10;
    	  int temp1=num/10;
    	  tens=temp1%10;
    	  int temp2=temp1/10;
    	  hundrds=temp2%10;
    	  //System.out.println(hundrds+" "+tens+" "+ones);
    	  if((tens==hundrds)&&(hundrds==ones))	// Working
    	  {
        	  //System.out.println("No pairs here");

    	  }
    	  else
    	  {
    		  pair_a=num;
    		  pair_b= tens*100+ ones*10+ hundrds;
    		  pair_c= ones*100 + hundrds*10 + tens;
    		  int nod_a=3;
    		  int nod_b = (int) Math.log10((double)pair_b)+1;
    		  int nod_c=  (int) Math.log10((double)pair_c)+1;
    		  if((nod_b==3)&&(nod_c==3))
    		  {
            	  //System.out.println("All have three digits");
            	  if((pair_b>=A)&&(pair_b<=B)&&(pair_c>=A)&&(pair_c<=B))
            	  {
                	  //System.out.println("Inside the case where all 3 pairs lie in the range");

                	  //System.out.println("pair a"+pair_a+" ");
					  //System.out.println("Incremented");

                	  pairs_3= pairs_3+1;    // As each pair will add 1 thus 3 will be added anyways

            	  }
            	  
            	  else if(((pair_b>=A) && (pair_b<=B)) || (pair_c>=A) && (pair_c<=B))
            	  {
                	  //System.out.println("Inside the case where only 2 pairs lie in the range");
					  //System.out.println("pair a"+ pair_a+"pair b"+ pair_b+"pair c"+ pair_c);
					  //System.out.println("Incremented");

            		  pairs_3= pairs_3+0.5;
            	  }
            	   
    		  }
    		  
    		  else if((nod_b==3)||(nod_c==3))
    		  {
				  //System.out.println("Inside case where only 2 numbers have 3 digits");

    			  if(nod_b==3)
    			  {
    				  if((pair_b>=A) && (pair_b<=B))
    				  {
    					  //System.out.println("pair a"+ pair_a+"pair b"+ pair_b+"pair c"+ pair_c);
    					  //System.out.println("Incremented");
    					  pairs_3= pairs_3+0.5;
    				  }
    				  
    			  }
    			  else if(nod_c==3)
    			  {
    				  if((pair_c>=A) && (pair_c<=B))
    				  {
    					  //System.out.println("pair a"+ pair_a+"pair b"+ pair_b+"pair c"+ pair_c);
    					  //System.out.println("Incremented");
    					  pairs_3= pairs_3+0.5;
    				  }
    			  }
    		  }
    		  
    	  }

      }
      
	  num++;
      }
	  
      
      pairs= pairs_2/2+pairs_3;
      
	  //System.out.println("Number of 2 digit pairs "+ pairs_2/2);
	  //System.out.println("Number of 3 digit pairs "+ pairs_3);
	  //System.out.println("Total number pairs "+ pairs);
      int ans = (int)pairs;
	  System.out.println("Case #"+line+": "+ans);

	  

}
	
}



	

