import java.util.*;
public class PrimeVisits {
public static void main(String args[]) {
Scanner scan=new Scanner(System.in);
// testcases
int t = scan.nextInt();
ArrayList list = new ArrayList<>();
while(t>0){
// input a and b
//boolean flag = true;
int count=0;
int a = scan.nextInt();
int b = scan.nextInt();
for(int i=a;i<=b;i++){
//for ith element
boolean flag = true;
for(int j=2;j<=i-1;j++){
if(i%j==0){
flag=false;
}
}
if(flag==false){
count++;
}
}
list.add(count);
t–;
}
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}
}
}