// Arup Guha
// 7/10/2014
// Solution to SI@UCF Week #1 Algorithms Contest Problem: Square Free

import java.util.*;

public class sqfree {

    final public static int MAX = 1000000;

    public static void main(String[] args) {

        // Initialize everything to be square free.
        int[] freq = new int[MAX+1];
        Arrays.fill(freq, 1);

        // Set all the perfect squares to be 0.
        for (int i=0; i*i<freq.length; i++)
            freq[i*i] = 0;

        // Change frequency array to be cumulative frequency.
        for (int i=1; i<freq.length; i++)
            freq[i] += freq[i-1];

        Scanner stdin = new Scanner(System.in);
        int numCases = stdin.nextInt();

        // We have all the answers, just look up =)
        for (int loop=0; loop<numCases; loop++) {

            // Subtract 1 from low so that this index is included in our count.
            // This is the standard technique to query a range from a cumulative frequency array.
            int low = stdin.nextInt() - 1;
            int high = stdin.nextInt();
            System.out.println(freq[high] - freq[low]);
        }
    }
}
