#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
const int maxn=1e6+10;
typedef long long ll;
bool pri[maxn];
int prime[maxn];
int cnt=0;
void init(){
rep(i,2,maxn){
if(!pri[i]){
prime[cnt++]=i;
for(ll j=1ll*i*i;j<maxn;j+=i){
pri[j]=1;
}
}
}
}
/*
形式一定要规整,要不然,缝隙太大,容易遗漏很多条件
*/
ll check(int id,int n){
ll ans=1,base=1ll*prime[id];
while(n){
if(n&1)ans*=1ll*base;
n>>=1;
base*=base;
}
return ans;
}
int getpos(int n){
int l=0,r=cnt-1,ans=0,mid;
while(l<=r){
mid=(l+r)>>1;
if(prime[mid]>n)
r=mid-1;
else{
ans=mid;
l=mid+1;
}
}
return ans;
}
int main(){
init();
int T;
scanf("%d",&T);
while(T--){
ll l,r;
scanf("%lld %lld",&l,&r);
int sr=sqrt(r+0.5);
int pos=getpos(sr);
int ans=0;
rep(i,0,pos+1){
ll tmp=1ll*prime[i];
tmp*=tmp;
for(;;){
if(tmp>r)break;
if(tmp>=l)ans++;
tmp*=1ll*prime[i];
}
}
printf("%d\n",ans);
}
return 0;
}