#include <bits/stdc++.h>
#define P(X) printf("db %d\n",X);
#define ll long long
#define rep(i,n) for(i=1;i<=n;i++)
using namespace std;
int pr[79500];
bool ar[1100005];
void siv()
{
int N=1000000,in=0,i,j,sq;
sq=sqrt(N);
for(i=4;i<=N;i+=2) ar[i]=1;
for(i=3;i<=sq;i+=2){
if(ar[i]==0)
{
for(j=i*i;j<=N;j+=i) ar[j]=1;
}
}
ar[1]=1;
for(i=1;i<N;i++){
if(!ar[i]){
in++;
pr[in]=i;
}
}
}
int fn(ll x)
{
int n=0,r=sqrt(x)+1,i,p;
for(i=1;pr[i]<=r;i++){
for(p=2;;p++){
if(pow(pr[i],p)>x)break;
}
n+=p-2;
}
return n;
}
int main()
{
int i,ts;
ll a,b;
//freopen("test.in","r",stdin);
scanf("%d",&ts);
siv();
//P(fn(3))
while(ts--){
scanf("%lld %lld",&a,&b);
printf("%d\n",fn(b)-fn(a-1));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgUChYKSBwcmludGYoImRiICVkXG4iLFgpOwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHJlcChpLG4pIGZvcihpPTE7aTw9bjtpKyspCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBwcls3OTUwMF07CmJvb2wgYXJbMTEwMDAwNV07CnZvaWQgc2l2KCkKewoJaW50IE49MTAwMDAwMCxpbj0wLGksaixzcTsKICAgIHNxPXNxcnQoTik7Cglmb3IoaT00O2k8PU47aSs9MikgYXJbaV09MTsKCWZvcihpPTM7aTw9c3E7aSs9Mil7CgkJaWYoYXJbaV09PTApCgkJewoJCQlmb3Ioaj1pKmk7ajw9TjtqKz1pKSBhcltqXT0xOwoJCX0KCX0KCWFyWzFdPTE7Cglmb3IoaT0xO2k8TjtpKyspewogICAgICAgIGlmKCFhcltpXSl7CiAgICAgICAgaW4rKzsKICAgICAgICBwcltpbl09aTsKICAgICAgICB9Cgl9Cn0KaW50IGZuKGxsI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