// Arup Guha
// 3/2/2020
// Solution? to 2020 Mercer Contest Problem #3: Leap Day

import java.util.*;

public class leapdaycount {

	final public static int START = 1600;
	final public static int END = 2100;
	
	public static void main(String[] args) {
	
		// Input range is small, so precompute a frequency array of leap years.
		int[] isleap = new int[END-START+2];
		for (int i=START; i<=END; i++) 
			isleap[i-START+1] = (i%4 == 0 && (i%100 != 0 || i%400 == 0)) ? 1 : 0;
		
		// Make cumulative frequency.
		for (int i=1; i<isleap.length; i++)
			isleap[i] += isleap[i-1];
		
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			// Get query.
			int s = stdin.nextInt();
			int e = stdin.nextInt();
			
			// Use cumulative frequency array to answer.
			int res = isleap[e-START+1] - isleap[s-START];
			
			// Output appropriately.
			if (res == 1)
				System.out.println("There is 1 leap year from "+s+" to "+e+".");
			else
				System.out.println("There are "+res+" leap years from "+s+" to "+e+".");
		
		}
	}
}