#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT ans=1) {

	for(; b; b>>=1, a=a*a) if(b&1) ans=ans*a;

	return ans;

}

#define NN 110

int nn, vst[NN];

INT p[NN];

void init() {

	for(int i=2; i<NN; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i+i; j<NN; j+=i) vst[j]=1;

	}

}

INT fff(INT n, INT ff) {

	INT xx=max((INT)pow(1.*n, 1./ff)-4LL, 0LL);

	while(power(xx, ff)<=n) xx++;

	return xx-2LL;

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT yy=max((INT)(log(xx)/log(2))-3LL, 0LL);

	while((1LL<<yy)<=xx) yy++;

	INT mmx=max(yy-1LL, 0LL);

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) {

			for(int k=j+1; k<nn; k++) if(p[i]*p[j]*p[k]<=mmx) {

				ans+=fff(xx, p[i]*p[j]*p[k]);

			}

		}

	}

	return ans+1;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n;

	INT l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1));

	}

}


#include <bits/stdc++.h>

using namespace std;

int n;
long long l, r, ta, tb;
vector< long long > v, vv;
vector< long long >::iterator ia, ib;

long long next(long long a) {
	long long re = sqrt((long double)a);
	while ((re - 1) * (re - 1) >= a)
		re--;
	while (re * re < a)
		re++;
	return re;
}

int main() {
	for (int i = 2; i <= 1000000; i++) {
		ta = i;
		ta *= i;
		while (i <= 1000000000000000000LL / ta) {
			ta *= i;
			tb = next(ta);
			if (tb * tb != ta)
				vv.push_back(ta);
		}
	}
	// printf("%d %lld %lld\n", vv.size(), vv.front(), vv.back());
	sort(vv.begin(), vv.end());
	for (int i = 0; i < vv.size(); i++)
		if (v.empty() || vv[i] != v.back())
			v.push_back(vv[i]);
	// printf("%d\n", v.size());
	scanf("%d", &n);
	while (n--) {
		scanf("%lld%lld", &l, &r);
		ta = next(l);
		tb = next(r + 1);
		printf("%lld\n", tb - ta + (upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l)));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

const ll Inf = 1000000000000000000ll;

int q;
vector <ll> seq;

ll Sqrt(ll x)
{
	ll res = ll(sqrt(ld(x)));
	while ((res + 1) * (res + 1) <= x) res++;
	while (res * res > x) res--;
	return res;
}

bool Square(ll x)
{
	ll g = Sqrt(x);
	return g * g == x;
}

int main()
{
	for (ll i = 2; i * i * i <= Inf; i++) {
		ll cur = i * i;
		while (cur <= Inf / i) {
			cur *= i;
			if (!Square(cur)) seq.push_back(cur);
		}
	}
	sort(seq.begin(), seq.end()); seq.erase(unique(seq.begin(), seq.end()), seq.end());
	scanf("%d", &q);
	while (q--) {
		ll lef, rig; scanf("%I64d %I64d", &lef, &rig);
		ll res = Sqrt(rig) - Sqrt(lef - 1);
		res += upper_bound(seq.begin(), seq.end(), rig) - lower_bound(seq.begin(), seq.end(), lef);
		printf("%I64d\n", res);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long>vec;
const long long hi=(long long)1e18;
map<long long,bool>M;
bool check(long long x){
    long long root=sqrt(x);
    return root*root!=x && !M[x];
}
void genSet(){
    for(int i=2;i<=1000000;i++){
        long long num=i;
        while(num<=hi/(long long)i){
            num*=i;
            if(check(num)){
                M[num]=true;
                vec.push_back(num);
            }
        }
    }
    sort(vec.begin(),vec.end());
    //for(int i=0;i<10;i++)cout<<vec[i]<<" ";puts("");
}
long long add(long long l,long long r){
    return floor(sqrt(r)-ceil(sqrt(l)))+1;
}
int main(){
    genSet();

    int q;
    scanf("%d",&q);
    while(q--){
        long long l,r;
        scanf("%lld %lld",&l,&r);

        long long ans=upper_bound(vec.begin(),vec.end(),r)-lower_bound(vec.begin(),vec.end(),l);
        //cout<<ans<<endl;
        ans+=add(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long>vec;
const long long hi=(long long)1e18;
map<long long,bool>M;

bool check(long long x){
    long long root=sqrt((long double)x);
    return root*root!=x && !M[x];
}
void genSet(){
    for(int i=2;i<=1000000;i++){
        long long num=i;
        while(num<=hi/(long long)i){
            num*=i;
            if(check(num)){
                M[num]=true;
                vec.push_back(num);
            }
        }
    }
    sort(vec.begin(),vec.end());
}
long long add(long long l,long long r){
    return floor(sqrt((long double)r)-ceil(sqrt((long double)l)))+1;
}
int main(){
    genSet();

    int q;
    scanf("%d",&q);
    while(q--){
        long long l,r;
        scanf("%lld %lld",&l,&r);

        long long ans=upper_bound(vec.begin(),vec.end(),r)-lower_bound(vec.begin(),vec.end(),l);
        ans+=add(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc1d(a) scanf("%lf",&a)
#define sc2d(a,b) scanf("%lf %lf",&a,&b)
#define sc3d(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define pfs(a) printf("%s",a)
#define pf1(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf1l(a) printf("%lld",a)
#define pf2l(a,b) printf("%lld %lld",a,b)
#define pf1d(a) printf("%lf",a)
#define pf2d(a,b) printf("%lf %lf",a,b)

#define br printf("\n")
#define ok printf("ok\n");

#define pf printf
#define sc scanf
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define pll pair<long long,long long>

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))

vector<int>prime;
vector<long double>vec;
long long func(long long l,long long r){
    long long ans=0;
    for(int i=0;i<prime.size();i++){
        int p=prime[i];

        long double z=1;
        long long x=pow((long double)l,z/(long double)p);
        long long y=pow((long double)r,z/(long double)p);

        long long num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        if(y<x)break;
        ans+=y-x+1;
    }
    //cout<<ans<<endl;
    for(int i=0;i<vec.size();i++){
        long long low=(long long)(pow(l,(long double)1.0/vec[i]));
        long long up=(long long)(pow(r,(long double)1.0/vec[i]));
        ans-=(up-low);
    }
    return ans;
}

void genPrime(){
    for(int i=2;i<=64;i++){
        bool flag=true;
        for(int j=2;j*j<=i && flag;j++){
            if(i%j==0)flag=false;
        }
        if(flag)prime.push_back(i);
    }
    for(int i=0;i<prime.size();i++){
        for(int j=i+1;j<prime.size();j++){
            if(prime[i]*prime[j]<64){
                vec.push_back(prime[i]*prime[j]);
            }

        }
    }
    sort(vec.begin(),vec.end());
    //for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
    //cout<<endl;
}
int main(){
    genPrime();

    int q;
    sc1(q);
    while(q--){
        long long l,r,ans=0;
        scanf("%lld %lld",&l,&r);
        if(l==1){
            ++ans;
            ++l;
        }
        ans+=func(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long>vec;
const long long hi=(long long)1e18;
map<long long,bool>M;
bool check(long long x){
    long long root=sqrtl(x);
    return root*root!=x && !M[x];
}
void genSet(){
    for(int i=2;i<=1000000;i++){
        long long num=i;
        while(num<=hi/(long long)i){
            num*=i;
            if(check(num)){
                M[num]=true;
                vec.push_back(num);
            }
        }
    }
    sort(vec.begin(),vec.end());
    //for(int i=0;i<10;i++)cout<<vec[i]<<" ";puts("");
}
long long add(long long l,long long r){
    return floor(sqrt(r)-ceil(sqrt(l)))+1;
}
int main(){
    genSet();

    int q;
    scanf("%d",&q);
    while(q--){
        long long l,r;
        scanf("%lld %lld",&l,&r);

        long long ans=upper_bound(vec.begin(),vec.end(),r)-lower_bound(vec.begin(),vec.end(),l);
        //cout<<ans<<endl;
        ans+=add(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc1d(a) scanf("%lf",&a)
#define sc2d(a,b) scanf("%lf %lf",&a,&b)
#define sc3d(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define pfs(a) printf("%s",a)
#define pf1(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf1l(a) printf("%lld",a)
#define pf2l(a,b) printf("%lld %lld",a,b)
#define pf1d(a) printf("%lf",a)
#define pf2d(a,b) printf("%lf %lf",a,b)

#define br printf("\n")
#define ok printf("ok\n");

#define pf printf
#define sc scanf
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define pll pair<long long,long long>

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))

vector<int>prime;
vector<long double>vec;
long long func(long long l,long long r){
    long long ans=0;
    for(int i=0;i<prime.size();i++){
        int p=prime[i];

        long double z=1;
        long long x=pow((long double)l,z/(long double)p);
        long long y=pow((long double)r,z/(long double)p);

        long long num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        num=1;
        for(int j=1;j<=p;j++)num*=(y+1);
        if(num<r)++y;

        if(y<x)break;
        ans+=y-x+1;
    }
    //cout<<ans<<endl;
    for(int i=0;i<vec.size();i++){
        long long low=pow(l,(long double)1.0/vec[i]);
        long long up=pow(r,(long double)1.0/vec[i]);
        ans-=(up-low);
    }
    return ans;
}

void genPrime(){
    for(int i=2;i<=64;i++){
        bool flag=true;
        for(int j=2;j*j<=i && flag;j++){
            if(i%j==0)flag=false;
        }
        if(flag)prime.push_back(i);
    }
    for(int i=0;i<prime.size();i++){
        for(int j=i+1;j<prime.size();j++){
            if(prime[i]*prime[j]<64)vec.push_back(prime[i]*prime[j]);
        }
    }
}
int main(){
    genPrime();

    int q;
    sc1(q);
    while(q--){
        long long l,r,ans=0;
        scanf("%lld %lld",&l,&r);
        if(l==1){
            ++ans;
            ++l;
        }
        ans+=func(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc1d(a) scanf("%lf",&a)
#define sc2d(a,b) scanf("%lf %lf",&a,&b)
#define sc3d(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define pfs(a) printf("%s",a)
#define pf1(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf1l(a) printf("%lld",a)
#define pf2l(a,b) printf("%lld %lld",a,b)
#define pf1d(a) printf("%lf",a)
#define pf2d(a,b) printf("%lf %lf",a,b)

#define br printf("\n")
#define ok printf("ok\n");

#define pf printf
#define sc scanf
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define pll pair<long long,long long>

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))

vector<int>prime;
vector<long double>vec;
long long func(long long l,long long r){
    long long ans=0;
    for(int i=0;i<prime.size();i++){
        int p=prime[i];

        long double z=1;
        long long x=pow((long double)l,z/(long double)p);
        long long y=pow((long double)r,z/(long double)p);

        long long num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        num=1;
        for(int j=1;j<=p;j++)num*=(y+1);
        if(num<r)++y;

        if(y<x)break;
        ans+=y-x+1;
    }
    //cout<<ans<<endl;
    for(int i=0;i<vec.size();i++){
        long long low=(long long)(pow(l,(long double)1.0/vec[i])+1e-9);
        long long up=(long long)(pow(r,(long double)1.0/vec[i])+1e-9);
        ans-=(up-low);
    }
    return ans;
}

void genPrime(){
    for(int i=2;i<=64;i++){
        bool flag=true;
        for(int j=2;j*j<=i && flag;j++){
            if(i%j==0)flag=false;
        }
        if(flag)prime.push_back(i);
    }
    for(int i=0;i<prime.size();i++){
        for(int j=i+1;j<prime.size();j++){
            if(prime[i]*prime[j]<64){
                vec.push_back(prime[i]*prime[j]);
            }

        }
    }
    sort(vec.begin(),vec.end());
    //for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
    //cout<<endl;
}
int main(){
    genPrime();

    int q;
    sc1(q);
    while(q--){
        long long l,r,ans=0;
        scanf("%lld %lld",&l,&r);
        if(l==1){
            ++ans;
            ++l;
        }
        ans+=func(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc1d(a) scanf("%lf",&a)
#define sc2d(a,b) scanf("%lf %lf",&a,&b)
#define sc3d(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define pfs(a) printf("%s",a)
#define pf1(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf1l(a) printf("%lld",a)
#define pf2l(a,b) printf("%lld %lld",a,b)
#define pf1d(a) printf("%lf",a)
#define pf2d(a,b) printf("%lf %lf",a,b)

#define br printf("\n")
#define ok printf("ok\n");

#define pf printf
#define sc scanf
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define pii pair<int,int>
#define pll pair<long long,long long>

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))

vector<int>prime;
//map<long long ,long long>M;
long long func(long long l,long long r){
    long long ans=0;
    for(int i=0;i<prime.size();i++){
        int p=prime[i];

        long double z=1;
        long long x=pow((long double)l,z/(long double)p);
        long long y=pow((long double)r,z/(long double)p);

        long long num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        num=1;
        for(int j=1;j<=p;j++)num*=x;
        if(num<l)++x;

        num=1;
        for(int j=1;j<=p;j++)num*=(y+1);
        if(num<r)++y;

        if(y<x)break;
        //cout<<endl;
        //cout<<x<<" "<<y<<" "<<p<<endl;
        ans+=y-x+1;

        /*for(int i=x;i<=y;i++){
            long long pp=1;
            for(int j=1;j<=p;j++){
                pp*=i;
            }
            if(M[pp]==0)M[pp]++;
            else {
                cout<<pp<<" "<<p<<endl;
            }
        }*/
    }
    //cout<<ans<<endl;
    for(int i=0;i<prime.size();i++){
        for(int j=i+1;j<prime.size();j++){
            long long low=pow(l,(long double)1.0/(long double)(prime[i]*prime[j]));
            long long up=pow(r,(long double)1.0/(long double)(prime[i]*prime[j]));
            ans-=(up-low);
        }
    }
    return ans;
}
void genPrime(){
    for(int i=2;i<=64;i++){
        bool flag=true;
        for(int j=2;j*j<=i && flag;j++){
            if(i%j==0)flag=false;
        }
        if(flag)prime.push_back(i);
    }
}
int main(){
    genPrime();

    int q;
    sc1(q);
    while(q--){
        long long l,r,ans=0;
        scanf("%lld %lld",&l,&r);
        if(l==1){
            ++ans;
            ++l;
        }
        ans+=func(l,r);

        printf("%lld\n",ans);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>

#define PP 60

using namespace std;
typedef long long int ll;

int ups[] = {0, 0, 1000000000, 999999, 31622, 3981, 999, 372, 177, 99, 63, 43, 31, 24, 19, 15, 13, 11, 9, 8, 7, 7, 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};

ll fpow(int b, int e) {
	if (b == 1) return 1;
	if (e == 0) return 1;

	if (e % 2 == 1) {
		return (ll)b * fpow(b, e-1);
	} else {
		ll a = fpow(b, e/2);
		return a * a;
	}
}

int pow_after(ll l, int e) {
	int s = 2, t = ups[e]+1;

	while (s < t) {
		int m = (s+t) / 2;
		ll a = fpow(m, e);
		if (a < l) {
			s = m+1;
		} else {
			t = m;
		}
	}

	return s;
};

int main() {
	ios_base::sync_with_stdio(0);

	vector<int> factors(PP, 0);
	vector<bool> nd(PP, true);

	for (int i = 2; i < PP; i++) {
		int j = i;
		int d = 2;
		int ct = 0;
		int ld = 0;
		while (j > 1) {
			if (j % d == 0) {
				if (ld == d) nd[i] = false;
				j /= d;
				ld = d;
				ct++;
			} else {
				d++;
			}
		}

		factors[i] = ct;
	}

	int z; cin >> z;
	while (z--) {
		ll l, r;
		cin >> l >> r;
		vector<int> powers(PP, 0);

		for (int p = 2; p < PP; p++) {
			int e = p;
			int ec = 1;
			while (e < PP && ec == 1) {
				int s = pow_after(l, e);
				int t = pow_after(r+1, e);
				powers[p] += (t - s) * ((ec == 1 || ec % 2 == 0) ? 1 : -1);
				e *= p;
				ec++;
			}
		}

		ll res = 0;

		for (int p = 2; p < PP; p++) {
			if (!nd[p]) continue;
			res += powers[p] * (factors[p] % 2 ? 1 : -1);
		}

		if (l == 1) res++;

		cout << res << endl;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
vector<long long>v1,v2;
long long sq(long long a)
{
	return a*a;
}
long long efcz(long long l,long long r)
{
	long long ans1,ans2,l1,r1,mid;
	l1=2;r1=1e9+1000;ans1=-1;
	while(l1<=r1)
	{
		mid=(l1+r1)/2;
		if(sq(mid)>=l) ans1=mid,r1=mid-1;
		else l1=mid+1;
	}
	l1=2;r1=1e9+1000;ans2=-1;
	while(l1<=r1)
	{
		mid=(l1+r1)/2;
		if(sq(mid)>r) ans2=mid,r1=mid-1;
		else l1=mid+1;
	}
	return ans2-ans1;
}
bool check(long long a)
{
	if(sq(sqrt(a))==a) return true;
	if(sq(sqrt(a)+1)==a) return true;
	if(sq(sqrt(a)-1)==a) return true;
	return false;
 }
int main()
{
	int i,j,k,q;
	long long r,l,ans,n;
	v1.clear();v2.clear();
	for(i=2;i<=1e6;i++)
	{
		long long e=i;
		for(j=2;j<=64;j++)
		{
			if(1e18/e<i) break;
			e*=i;
			if(j!=2) v1.push_back(e);
		}
	}
	sort(v1.begin(),v1.end());
	v1.erase(unique(v1.begin(),v1.end()),v1.end());
	int size=v1.size();
	for(i=0;i<size;i++) if(!check(v1[i])) v2.push_back(v1[i]);
	cin>>n;
	for(i=0;i<n;i++)
	{
		ans=0;
		cin>>l>>r;
		if(l<=1) ans++;
		ans+=upper_bound(v2.begin(),v2.end(),r)-lower_bound(v2.begin(),v2.end(),l);
		//cout<<"qqqqqqqqqqq"<<endl;
		ans+=efcz(l,r);
		cout<<ans<<endl;
	}
}


#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
using namespace std;
typedef long long LL;
set<LL> s;
int q;
LL l, r, a[5000000];

LL count(LL n)
{
	if (!n) return 0;
	LL p = sqrt(n);
	int l = 1, r = a[0];
	while(l != r)
	{
		int mid = (l + r + 1) / 2;
		if (a[mid] > n) r = mid - 1; else l = mid;
	}
	return l + p - 1;
}

int main()
{
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	for(LL k = 2; k <= 1000000; k ++)
	  for(LL t = k * k * k; t <= 1e18; t = t * k)
	  {
	  	LL p = sqrt(t);
	  	if (p * p != t) s.insert(t);
	  	if (log10(t) + log10(k) > 18) break;
	  }
	a[a[0] = 1] = 1;
	for(set<LL>:: iterator it = s.begin(); it != s.end(); it ++) a[++ a[0]] = * it;
	//	cout << a[0] << endl;
	//return 0;
	//for(int i = 1; i <= 100; i ++) cout << a[i] << endl;
	//cout << LL(sqrt(63)) << endl;
	cin >> q;
	while(q --)
	{
		cin >> l >> r;
		cout << count(r) - count(l - 1) << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
int Q;
LL l, r, sum[70];

int root(LL n, int k)
{
	int t = (int)pow(n, 1.0 / k);
	double p = 1;
	for(int i = 1; i <= k; i ++) p = p * t;
	//if (f) cout << p << ' ' << n << endl;
	if (LL(p) > n) t --;
  return t;
}

LL count(LL n)
{
	if (n == 0) return 0;
	LL ret = 1;
	for(int i = 62; i > 1; i --)
	{
		LL t = root(n, i);
		//cout << i << ' ' << t << endl;
		if (t > 1)
		{
			sum[i] = t - 1;
			for(int j = i + 1; j <= 62; j ++)
				if (j % i == 0) sum[i] = sum[i] - sum[j];
		}
		else sum[i] = 0;
		ret += sum[i];
	}
	return ret;
}

int main()
{
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> Q;
//	LL k = 1;
//	for(int i = 1; i <= 37; i ++) k = k * 3;
	//	cout << k << endl;
//	cout << count(999999999999999999) << endl;
//	cout << count(1000000000000000000) << endl;
	//for(int i = 1; i <= 1000; i ++) cout << i << ' ' << count(i) << endl;
	while(Q --)
	{
		cin >> l >> r;
		cout << count(r) - count(l - 1) << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
int Q;
LL l, r, sum[70];

int root(LL n, int k)
{
	int t = (int)pow(n, 1.0 / k);
	if (pow(t + 1, k) <= n) return t + 1;
	if (pow(t, k) <= n) return t;
	if (pow(t - 1, k) <= n) return t - 1;
	return t - 2;
}

LL count(LL n)
{
	if (n == 0) return 0;
	LL ret = 1;
	for(int i = 60; i > 1; i --)
	{
		int t = root(n, i);
		if (t > 1)
		{
			sum[i] = t - 1;
			for(int j = i + 1; j <= 60; j ++)
				if (j % i == 0) sum[i] = sum[i] - sum[j];
		}
		else sum[i] = 0;
		ret += sum[i];
	}
	return ret;
}

int main()
{
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> Q;
	while(Q --)
	{
		cin >> l >> r;
		cout << count(r) - count(l - 1) << endl;
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL n) {
	LL l=0,r=n,mid;
	while(l<r) {
		mid=(l+r+1)/2ll;
		if(mid>n/mid) r=mid-1;
		//else if(mid==n) return mid;
		else l=mid;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	for(int i=2;i<=e;i++) ret*=k;
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{

		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);

		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow(mysqrt(a[i]),2)!=a[i]))
		{
			b[++cnt1]=a[i];
		}
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll/j;j*=i)
		{
			a[++cnt]=j;
			if (j > 1000000000000000000ll / i) break;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[0]=0;

}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll;j*=i)
		{
			a[++cnt]=j;
			if (j > 1000000000000000000ll / i) break;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[0]=0;

}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll/j;j*=i)
		{
			a[++cnt]=j;
			if (j > 1000000000000000000ll / i) break;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[0]=0;
	b[++cnt1]=LLinf;
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll/j;j*=i)
		{
			a[++cnt]=j;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[++cnt1]=inf;
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll/j;j*=i)
		{
			a[++cnt]=j;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll;j*=i)
		{
			a[++cnt]=j;
			if (j > 1000000000000000000ll / i) break;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[0]=0;

}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	//cout<<'t'<<'\n';
	for(int i=2;i<=e;i++) ret*=k;
	//cout<<ret<<' '<<e<<'\n';
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{
		//会爆LL
		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);
			//cout<<cnt<<'\n';
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow((int)sqrt(a[i]+0.5),2))!=a[i])
		{
			b[++cnt1]=a[i];
		}

	//cout<<cnt<<'\n';
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		if(a[l]<L) l++;
		if(a[r]<=R) r++;
		res=(LL)sqrt(R+0.5)-(LL)sqrt(L-0.5)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	//int a[]={0,1,2,3,4,5};
	//printf("%d %d\n",lower_bound(a+1,a+5+1,3)-a,upper_bound(a+1,a+5+1,3)-a);
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

/*
LL mysqrt(LL n) {
	LL l=0,r=n,mid;
	while(l<r) {
		mid=(l+r+1)/2ll;
		if(mid>n/mid) r=mid-1;
		//else if(mid==n) return mid;
		else l=mid;
	}
	return l;
}*/
LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	for(int i=2;i<=e;i++) ret*=k;
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{

		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);

		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow(mysqrt(a[i]),2)!=a[i]))
		{
			b[++cnt1]=a[i];
		}
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

/*
LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}*/

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll;j*=i)
		{
			a[++cnt]=j;
			if (j > 1000000000000000000ll / i) break;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=(LL)sqrt(a[i]+0.5);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[0]=0;

}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		res=(LL)sqrt(R+0.5)-(LL)sqrt(L-0.5)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL n) {
	LL l=0,r=n,mid;
	while(l<r) {
		mid=(l+r+1)/2ll;
		if(mid>n/mid) r=mid-1;
		//else if(mid==n) return mid;
		else l=mid;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	for(int i=2;i<=e;i++) ret*=k;
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{

		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);

		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&((quickpow((int)sqrt(a[i]+0.5),2))!=a[i]))
		{
			b[++cnt1]=a[i];
		}
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	//cout<<'t'<<'\n';
	for(int i=2;i<=e;i++) ret*=k;
	//cout<<ret<<' '<<e<<'\n';
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{
		//会爆LL
		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);
			//cout<<cnt<<'\n';
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow((int)sqrt(a[i]+0.5),2))!=a[i])
		{
			b[++cnt1]=a[i];
		}

	//cout<<cnt<<'\n';
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		if(a[l]<L) l++;
		if(a[r]<=R) r++;
		res=(LL)sqrtl(R+0.5)-(LL)sqrtl(L-0.5)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	//int a[]={0,1,2,3,4,5};
	//printf("%d %d\n",lower_bound(a+1,a+5+1,3)-a,upper_bound(a+1,a+5+1,3)-a);
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll/j;j*=i)
		{
			a[++cnt]=j;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
	b[++cnt1]=LLinf;
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		printf("%I64d\n",res);
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	//cout<<'t'<<'\n';
	for(int i=2;i<=e;i++) ret*=k;
	//cout<<ret<<' '<<e<<'\n';
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{
		//会爆LL
		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);
			//cout<<cnt<<'\n';
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow((int)sqrt(a[i]+0.5),2))!=a[i])
		{
			b[++cnt1]=a[i];
		}

	//cout<<cnt<<'\n';
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		if(a[l]<L) l++;
		if(a[r]<=R) r++;
		res=(LL)sqrt(R+0.5)-(LL)sqrt(L-0.5)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	int a[]={0,1,2,3,4,5};
	printf("%d %d\n",lower_bound(a+1,a+5+1,3)-a,upper_bound(a+1,a+5+1,3)-a);
	//build();
	//solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL x) {
	LL l = 0, r = 1e9 + 1;
	while (l < r - 1) {
		LL m = (l + r) / 2;
		if (m * m > x)
			r = m;
		else
			l = m;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

void build()
{
	for(LL i=2;i<=1000000;i++)
	{

		for(LL j=i*i*i;j<=1000000000000000000ll/j;j*=i)
		{
			a[++cnt]=j;
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
	{
		LL t=mysqrt(a[i]);
		if(t*t!=a[i] && a[i]!=b[cnt1]) b[++cnt1]=a[i];
	}
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=lower_bound(b+1,b+cnt1+1,R)-b;
		while(b[l]<L) l++;
		while(b[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		cout<<res<<'\n';
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	//cout<<'t'<<'\n';
	for(int i=2;i<=e;i++) ret*=k;
	//cout<<ret<<' '<<e<<'\n';
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{
		//会爆LL
		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);
			//cout<<cnt<<'\n';
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow((int)sqrt(a[i]+0.5),2))!=a[i])
		{
			b[++cnt1]=a[i];
		}

	//cout<<cnt<<'\n';
}

void solve()
{
	//scanf("%I64d",&n);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>L>>R;
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		res=(LL)sqrt(R+0.5)-(LL)sqrt(L-0.5)+r-l;
		//cout<<a[l-1]<<' '<<a[l]<<' '<<a[r-1]<<' '<<a[r]<<' '<<res<<'\n';
		cout<<res<<'\n';
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	//cout<<'t'<<'\n';
	for(int i=2;i<=e;i++) ret*=k;
	//cout<<ret<<' '<<e<<'\n';
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{
		//会爆LL
		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);
			//cout<<cnt<<'\n';
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow((int)sqrt(a[i]+0.5),2))!=a[i])
		{
			b[++cnt1]=a[i];
		}

	//cout<<cnt<<'\n';
}

LL mysqrt(LL n) {
	LL l=0,r=n,mid;
	while(l<r) {
		//printf("%d %d\n",l,r);
		mid=(l+r+1)>>1;
		if(mid*mid>n) r=mid-1;
		else if(mid*mid==n) return mid;
		else l=mid;
	}
	return l;
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		if(a[l]<L) l++;
		if(a[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		//printf("test %d %d\n",mysqrt(L-1),mysqrt(R));
		cout<<res<<'\n';
	}

}

int main()
{
	//printf("%d\n",mysqrt(8));
	//int a[]={0,1,2,3,4,5};
	//printf("%d %d\n",lower_bound(a+1,a+5+1,3)-a,upper_bound(a+1,a+5+1,3)-a);
	build();
	solve();

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
   	LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
    return x*f;
}

LL mysqrt(LL n) {
	LL l=0,r=n,mid;
	while(l<r) {
		mid=(l+r+1)/2ll;
		if(mid>n/mid) r=mid-1;
		//else if(mid==n) return mid;
		else l=mid;
	}
	return l;
}

const int maxn = 10000000 + 10;
LL a[maxn],b[maxn],cnt,cnt1;
LL n,L,R;
LL l,r,res;

LL quickpow(LL k,LL e) {
	LL ret=k;
	for(int i=2;i<=e;i++) ret*=k;
	return ret;
}

void build()
{
	for(LL i=3;i<=65;i++)
	{
		//会爆LL
		for(LL j=2ll;quickpow(j,i-1)<=1000000000000000000ll/j;j++)
		{
			a[++cnt]=quickpow(j,i);
			//cout<<cnt<<'\n';
		}
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(a[i]!=b[cnt1]&&(quickpow((int)sqrt(a[i]+0.5),2))!=a[i])
		{
			b[++cnt1]=a[i];
		}

	//cout<<cnt<<'\n';
}

void solve()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		L=read(); R=read();
		l=lower_bound(b+1,b+cnt1+1,L)-b;
		r=upper_bound(b+1,b+cnt1+1,R)-b;
		if(a[l]<L) l++;
		if(a[r]<=R) r++;
		res=mysqrt(R)-mysqrt(L-1)+r-l;
		//cout<<mysqrt(R)<<' '<<mysqrt(L-1)<<'\n';
		cout<<res<<'\n';
	}

}

int main()
{
	build();
	solve();

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

const int N=65;
#define eps 1e-8

int prime[N],isprime[N];

void getPrime()
{
    int i,j;
    prime[0]=0;
    for(i=0; i<N; i++)
        isprime[i]=1;
    for(i=2; i<N; i++)
        if(isprime[i])
        {
            prime[++prime[0]]=i;
            for(j=2; i*j<N; j++)
                isprime[i*j]=0;
        }
}

int main()
{

    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    long long n,tmp,m;
    getPrime();
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        long long t_n=n;
        int ans=1;
        for(int i=1; i<=prime[0]; i++)
        {
            tmp=(long long)(pow((double)n,1.0/prime[i])+eps);   //不加eps则WA
            if(tmp==1)      //减枝，下同
                break;
            ans+=tmp-1;
        }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
            {
                tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]))+eps);
                if(tmp==1)
                    break;
                ans-=(tmp-1);
            }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
                for(int k=j+1; k<=prime[0]; k++)
                {
                    tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]*prime[k]))+eps);
                    if(tmp==1)
                        break;
                    ans+=(tmp-1);
                }
        long long L_ans=ans;
        n=m;
        ans=1;
        for(int i=1; i<=prime[0]; i++)
        {
            tmp=(long long)(pow((double)n,1.0/prime[i])+eps);   //不加eps则WA
            if(tmp==1)      //减枝，下同
                break;
            ans+=tmp-1;
        }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
            {
                tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]))+eps);
                if(tmp==1)
                    break;
                ans-=(tmp-1);
            }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
                for(int k=j+1; k<=prime[0]; k++)
                {
                    tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]*prime[k]))+eps);
                    if(tmp==1)
                        break;
                    ans+=(tmp-1);
                }
        long long R_ans=ans;
        long long res=R_ans-L_ans;
        bool flag=false;
        if(t_n==1)
            flag=true;
        else
        {
            n=t_n-1;
            ans=1;
            for(int i=1; i<=prime[0]; i++)
            {
                tmp=(long long)(pow((double)n,1.0/prime[i])+eps);   //不加eps则WA
                if(tmp==1)      //减枝，下同
                    break;
                ans+=tmp-1;
            }
            for(int i=1; i<=prime[0]; i++)
                for(int j=i+1; j<=prime[0]; j++)
                {
                    tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]))+eps);
                    if(tmp==1)
                        break;
                    ans-=(tmp-1);
                }
            for(int i=1; i<=prime[0]; i++)
                for(int j=i+1; j<=prime[0]; j++)
                    for(int k=j+1; k<=prime[0]; k++)
                    {
                        tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]*prime[k]))+eps);
                        if(tmp==1)
                            break;
                        ans+=(tmp-1);
                    }
        }
        if(flag||ans!=L_ans)
            cout<<res+1<<endl;
        else
            cout<<res<<endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int prime[20]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};
long long ans,n,m;
int i;
void dfs(int j,int num,int p)
{
    if(p==0)
    {
        long long t=pow(n,1.0/num);
        if(pow(t,0.0+num)>n)  t--;
        t--;
        if(t>0)
            //i为奇数则加，否则减
            ans+=t*(i&1?1:-1);
        /*if(i%2==1)
            ans+=t*i;
        else
            ans-=t*i;*/
        return ;
    }
    if(j>=17)
        return;//超出60以内素数，不予考虑
    if(num*prime[j]<60) //仍在范围内，继续搜
        dfs(j+1,num*prime[j],p-1);
    dfs(j+1,num,p);
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        scanf("%I64d%I64d",&n,&m);
        long long tmp_n=n;
        ans=0;
        for(i=1; i<=3; i++)
            dfs(0,1,i);
        long long t_ans=ans+1;
        cout<<t_ans<<endl;
        ans=0;
        n=m;
        for(i=1; i<=3; i++)
            dfs(0,1,i);
        ans++;
        cout<<ans<<endl;
        long long res=ans-t_ans;
        //检验n
        bool flag=false;
        if(tmp_n==1)
            flag=true;
        else
        {
            ans=0;
            n=tmp_n-1;
            for(i=1; i<=3; i++)
                dfs(0,1,i);
            ans++;
        }
        if(ans!=t_ans||flag)
            cout<<"oh"<<res+1<<endl;
        else
            cout<<res<<endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
long long result(long long x)
{
    int i,j,k;
    long long tmp,ans=1;
    for(i=0;;i++)
    {
        tmp=(long long)(pow(x,1.0/prime[i]));
        if(tmp<2)
            break;
        ans+=tmp-1;
        for(j=i+1;;j++)
        {
            tmp=(long long)(pow(x,1.0/(prime[i]*prime[j])));
            if(tmp<2)
                break;
            ans-=tmp-1;
            for(k=j+1;;k++)
            {
                tmp=(long long)(pow(x,1.0/(prime[i]*prime[j]*prime[k])));
                if(tmp<2)
                    break;
                ans+=tmp-1;
            }
        }
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        long long L,R;
        cin>>L>>R;
        long long L_ans=result(L);
        long long R_ans=result(R);
        bool flag=false;
        long long t_ans;
        if(L==1)
            flag=true;
        else
            t_ans=result(L-1);
        if(flag||t_ans!=L_ans)
            cout<<R_ans-L_ans+1<<endl;
        else
            cout<<R_ans-L_ans<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

const int N=65;
#define eps 1e-8

int prime[N],isprime[N];

void getPrime()
{
    int i,j;
    prime[0]=0;
    for(i=0; i<N; i++)
        isprime[i]=1;
    for(i=2; i<N; i++)
        if(isprime[i])
        {
            prime[++prime[0]]=i;
            for(j=2; i*j<N; j++)
                isprime[i*j]=0;
        }
}

int main()
{

    //freopen("input.txt","r",stdin);

    long long n,tmp,m;
    getPrime();
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        long long t_n=n;
        int ans=1;
        for(int i=1; i<=prime[0]; i++)
        {
            tmp=(long long)(pow((double)n,1.0/prime[i])+eps);   //不加eps则WA
            if(tmp==1)      //减枝，下同
                break;
            ans+=tmp-1;
        }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
            {
                tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]))+eps);
                if(tmp==1)
                    break;
                ans-=(tmp-1);
            }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
                for(int k=j+1; k<=prime[0]; k++)
                {
                    tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]*prime[k]))+eps);
                    if(tmp==1)
                        break;
                    ans+=(tmp-1);
                }
        long long L_ans=ans;
        n=m;
        ans=1;
        for(int i=1; i<=prime[0]; i++)
        {
            tmp=(long long)(pow((double)n,1.0/prime[i])+eps);   //不加eps则WA
            if(tmp==1)      //减枝，下同
                break;
            ans+=tmp-1;
        }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
            {
                tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]))+eps);
                if(tmp==1)
                    break;
                ans-=(tmp-1);
            }
        for(int i=1; i<=prime[0]; i++)
            for(int j=i+1; j<=prime[0]; j++)
                for(int k=j+1; k<=prime[0]; k++)
                {
                    tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]*prime[k]))+eps);
                    if(tmp==1)
                        break;
                    ans+=(tmp-1);
                }
        long long R_ans=ans;
        long long res=R_ans-L_ans;
        bool flag=false;
        if(t_n==1)
            flag=true;
        else
        {
            n=t_n-1;
            ans=1;
            for(int i=1; i<=prime[0]; i++)
            {
                tmp=(long long)(pow((double)n,1.0/prime[i])+eps);   //不加eps则WA
                if(tmp==1)      //减枝，下同
                    break;
                ans+=tmp-1;
            }
            for(int i=1; i<=prime[0]; i++)
                for(int j=i+1; j<=prime[0]; j++)
                {
                    tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]))+eps);
                    if(tmp==1)
                        break;
                    ans-=(tmp-1);
                }
            for(int i=1; i<=prime[0]; i++)
                for(int j=i+1; j<=prime[0]; j++)
                    for(int k=j+1; k<=prime[0]; k++)
                    {
                        tmp=(long long)(pow((double)n,1.0/(prime[i]*prime[j]*prime[k]))+eps);
                        if(tmp==1)
                            break;
                        ans+=(tmp-1);
                    }
        }
        if(flag||ans!=L_ans)
            cout<<res+1<<endl;
        else
            cout<<res<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXS = 1000 * 1000 * 1000 + 10;
const long long MAXR = 1500ll * 1000 * 1000 * 1000 * 1000;
const int MAXX = 1000 * 1000 + 10;
const int MAXQ = 100 * 1000 + 10;

typedef pair<long long, int> pii;

int findSqrt(long long x)
{
	int lo = 0, hi = MAXS;
	while (hi - lo > 1)
	{
		int mid = (lo + hi) / 2;
		if ((long long)mid * mid >= x)
			hi = mid;
		else
			lo = mid;
	}
	return lo;
}

int ans[MAXQ];
bool mrk[MAXX];
vector<pii> v;
int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		long long l, r;
		cin >> l >> r;
		r++;
		v.push_back(pii(l, -(i + 1)));
		v.push_back(pii(r, i));
		ans[i] = findSqrt(r) - findSqrt(l);
	}

	sort(v.begin(), v.end());
	for (int i = 2; i <= MAXX; i++)
	{
		if (mrk[i])
			continue;

		for (long long x = (long long)i * i; x <= MAXX; x *= i)
			mrk[x] = true;
		int ptr = 0;
		long long x = i;
		int cnt = 0;
		long long i2 = (long long)i * i;
		while (ptr < v.size() && v[ptr].first <= x)
			ptr++;
		while (ptr < v.size() && x < MAXR / i2)
		{
			x *= i2;
			while (ptr < v.size() && v[ptr].first <= x)
			{
				if (v[ptr].second < 0)
					ans[-v[ptr].second - 1] -= cnt;
				else
					ans[v[ptr].second] += cnt;
				ptr++;
			}
			cnt++;
		}
		while (ptr < v.size())
		{
			if (v[ptr].second < 0)
				ans[-v[ptr].second - 1] -= cnt;
			else
				ans[v[ptr].second] += cnt;
			ptr++;
		}
	}
	for (int i = 0; i < q; i++)
		cout << ans[i] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXS = 1000 * 1000 * 1000 + 10;
const long long MAXR = 1500ll * 1000 * 1000 * 1000 * 1000;
const int MAXX = 1000 * 1000 + 10;
const int MAXQ = 100 * 1000 + 10;

typedef pair<long long, int> pii;

int findSqrt(long long x)
{
	int lo = 0, hi = MAXS;
	while (hi - lo > 1)
	{
		int mid = (lo + hi) / 2;
		if ((long long)mid * mid >= x)
			hi = mid;
		else
			lo = mid;
	}
	return lo;
}

int ans[MAXQ];
bool mrk[MAXX];
vector<pii> v;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		long long l, r;
		cin >> l >> r;
		r++;
		v.push_back(pii(l, -(i + 1)));
		v.push_back(pii(r, i));
		ans[i] = findSqrt(r) - findSqrt(l);
	}

	sort(v.begin(), v.end());
	for (int i = 2; i <= MAXX; i++)
	{
		if (mrk[i])
			continue;

		for (long long x = (long long)i * i; x <= MAXX; x *= i)
			mrk[x] = true;
		int ptr = 0;
		long long x = i;
		int cnt = 0;
		long long i2 = (long long)i * i;
		while (ptr < v.size() && v[ptr].first <= x)
			ptr++;
		while (ptr < v.size() && x < MAXR / i2)
		{
			x *= i2;
			while (ptr < v.size() && v[ptr].first <= x)
			{
				if (v[ptr].second < 0)
					ans[-v[ptr].second - 1] -= cnt;
				else
					ans[v[ptr].second] += cnt;
				ptr++;
			}
			cnt++;
		}
		while (ptr < v.size())
		{
			if (v[ptr].second < 0)
				ans[-v[ptr].second - 1] -= cnt;
			else
				ans[v[ptr].second] += cnt;
			ptr++;
		}
	}
	for (int i = 0; i < q; i++)
		cout << ans[i] << '\n';

}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXS = 1000 * 1000 * 1000 + 10;
const long long MAXR = 1500ll * 1000 * 1000 * 1000 * 1000 * 1000;
const int MAXX = 1000 * 1000 + 10;
const int MAXQ = 100 * 1000 + 10;

typedef pair<long long, int> pii;

int findSqrt(long long x)
{
	int lo = 0, hi = MAXS;
	while (hi - lo > 1)
	{
		int mid = (lo + hi) / 2;
		if ((long long)mid * mid >= x)
			hi = mid;
		else
			lo = mid;
	}
	return lo;
}

int ans[MAXQ];
int res[MAXQ * 2];
bool mrk[MAXX];
vector<pii> v;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		long long l, r;
		cin >> l >> r;
		r++;
		v.push_back(pii(l, -(i + 1)));
		v.push_back(pii(r, i));
		ans[i] = findSqrt(r) - findSqrt(l);
	}
	sort(v.begin(), v.end());
	for (int i = 2; i <= MAXX; i++)
	{
		if (mrk[i])
			continue;
		long long i2 = (long long)i * i;
		for (long long x = i2; x <= MAXX; x *= i)
			mrk[x] = true;
		long long x = i;
		while (x < MAXR / i2)
		{
			x *= i2;
			int ptr = upper_bound(v.begin(), v.end(), pii(x, q)) - v.begin();
			if (ptr == v.size())
				break;
			res[ptr]++;
		}
	}
	int sum = 0;
	for (int i = 0; i < v.size(); i++)
	{
		sum += res[i];
		if (v[i].second < 0)
			ans[-v[i].second -1] -= sum;
		else
			ans[v[i].second] += sum;
	}
	for (int i = 0; i < q; i++)
		cout << ans[i] << '\n';

}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXS = 1000 * 1000 * 1000 + 10;
const long long MAXR = 1500ll * 1000 * 1000 * 1000 * 1000;
const int MAXX = 1000 * 1000 + 10;
const int MAXQ = 100 * 1000 + 10;

typedef pair<long long, int> pii;

int findSqrt(long long x)
{
	int lo = 0, hi = MAXS;
	while (hi - lo > 1)
	{
		int mid = (lo + hi) / 2;
		if ((long long)mid * mid >= x)
			hi = mid;
		else
			lo = mid;
	}
	return lo;
}

int ans[MAXQ];
int res[MAXQ * 2];
bool mrk[MAXX];
vector<pii> v;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		long long l, r;
		cin >> l >> r;
		r++;
		v.push_back(pii(l, -(i + 1)));
		v.push_back(pii(r, i));
		ans[i] = findSqrt(r) - findSqrt(l);
	}

	sort(v.begin(), v.end());
	for (int i = 2; i <= MAXX; i++)
	{
		if (mrk[i])
			continue;
		long long i2 = (long long)i * i;
		for (long long x = i2; x <= MAXX; x *= i)
			mrk[x] = true;
		long long x = i;
		while (x < MAXR / i2)
		{
			x *= i2;
			int ptr = upper_bound(v.begin(), v.end(), pii(x, q)) - v.begin();
			if (ptr == v.size())
				break;
			res[ptr]++;
		}
	}
	int sum = 0;
	for (int i = 0; i < v.size(); i++)
	{
		sum += res[i];
		if (v[i].second < 0)
			ans[-v[i].second -1] -= sum;
		else
			ans[v[i].second] += sum;
	}
	for (int i = 0; i < q; i++)
		cout << ans[i] << '\n';

}


#include<bits/stdc++.h>
using namespace std;
const long long ma = 1e18;
long long T, l, r, n, a[1050000];
long long solve(long long x)
{
    if(x == 0) return 0;
    return (long long)sqrt(x)+(upper_bound(a, a+n, x)-a);
}
int main()
{
    scanf("%I64d",&T);
    for(long long i=2;i*i*i<=ma;i++)
    {
        for(long long j=i;j<=ma/(i*i);j*=(i*i))
        {
            long long temp=sqrt(j*i*i);
            if(temp*temp!=j*i*i)
                a[n++]=j*i*i;
        }
    }
    sort(a,a+n);
    n=unique(a,a+n)-a;
    while(T--)
    {
        scanf("%I64d%I64d",&l,&r);
        printf("%I64d\n",solve(r)-solve(l-1));
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const int MAX=1e6+5;
vector<LL>ok;
LL ksm(int a,int x)
{
    if(x==0)return 1;
    LL tmp=ksm(a,x/2);
    if(x&1)return tmp*tmp*a;
    return tmp*tmp;
}
vector<LL>::iterator tail;
void init()
{
    ok.clear();
    //int cnt=0;
    for(int i=2;i<=1e6;i++)
    {
        if((int)sqrt(i)*(int)sqrt(i)<i)
        {
            //cnt++;
            LL tmp=(LL)i;
            int t=(int)((int)(log(1e18)/log(i))+0.1);
            for(int j=2;j<=t;j++)
            {
                tmp*=(LL)i;
                if(j&1)ok.push_back(tmp);
                //if(tmp>(LL)1e18/(LL)i)break;
            }
        }
    }
    //cout<<cnt<<endl;
    sort(ok.begin(),ok.end());
    tail=unique(ok.begin(),ok.end());
}
LL ask(LL x)
{
    if(x==0)return 0;
    if(x==1)return 1;
    //cout<<sqrt(x)<<" "<<upper_bound(ok.begin(),tail,x)-ok.begin()<<endl;
    return (LL)sqrt(x)+(LL)(upper_bound(ok.begin(),tail,x)-ok.begin());
}
int main()
{
    init();
    int cas;
    scanf("%d",&cas);
    while(cas--)
    {
        LL l,r;
        cin>>l>>r;
        cout<<ask(r)-ask(l-1)<<endl;
        /*cin>>l;
        cout<<ask(l)<<endl;*/
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const int MAX=1e6+5;
vector<LL>ok;
LL ksm(int a,int x)
{
    if(x==0)return 1;
    LL tmp=ksm(a,x/2);
    if(x&1)return tmp*tmp*a;
    return tmp*tmp;
}
vector<LL>::iterator tail;
void init()
{
    ok.clear();
    for(int i=2;i<=1e6;i++)
    {
        if(sqrt(i)*sqrt(i)!=i)
        {
            LL tmp=(LL)i;
            for(int j=2;;j++)
            {
                tmp*=(LL)i;
                if(j&1)ok.push_back(tmp);
                if(tmp>(LL)1e18/(LL)i)break;
            }
        }
    }
    sort(ok.begin(),ok.end());
    tail=unique(ok.begin(),ok.end());
    /*for(vector<LL>::iterator it=ok.begin();it!=tail;it++)
    {
        if(*it>100)break;
        cout<<*it<<" ";
    }cout<<endl;*/
}
int ask(LL x)
{
    if(x==0)return 0;
    if(x==1)return 1;
    return sqrt(x)+(lower_bound(ok.begin(),tail,x)-ok.begin());
}
int main()
{
    init();
    int cas;
    scanf("%d",&cas);
    while(cas--)
    {
        LL l,r;
        //scanf("%lld%lld",&l,&r);
        //printf("%lld\n",ask(r)-ask(l));
        cin>>l>>r;
        cout<<ask(r)-ask(l-1)<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const int MAX=1e6+5;
vector<LL>ok;
LL ksm(int a,int x)
{
    if(x==0)return 1;
    LL tmp=ksm(a,x/2);
    if(x&1)return tmp*tmp*a;
    return tmp*tmp;
}
vector<LL>::iterator tail;
void init()
{
    ok.clear();
    for(int i=2;i<=1e6;i++)
    {
        if(sqrt(i)*sqrt(i)!=i)
        {
            LL tmp=(LL)i;
            for(int j=2;;j++)
            {
                tmp*=(LL)i;
                if(j&1)ok.push_back(tmp);
                if(tmp>(LL)1e18/(LL)i)break;
            }
        }
    }
    sort(ok.begin(),ok.end());
    tail=unique(ok.begin(),ok.end());
    /*for(vector<LL>::iterator it=ok.begin();it!=tail;it++)
    {
        if(*it>100)break;
        cout<<*it<<" ";
    }cout<<endl;*/
}
int ask(LL x)
{
    if(x==0)return 0;
    if(x==1)return 1;
    return sqrt(x)+(upper_bound(ok.begin(),tail,x)-ok.begin());
}
int main()
{
    init();
    int cas;
    scanf("%d",&cas);
    while(cas--)
    {
        LL l,r;
        cin>>l>>r;
        cout<<ask(r)-ask(l-1)<<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];
/*
inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		if(ans>num/x)return false;
		ans=ans*x;
	}
	return true;
}*/

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll n,m1,m2,a,b,t,l,r;
bool vis[10000005];

inline ll calc(ll n){
	if(n==0)return 0;
	memset(vis,0,sizeof vis);
	m1=sqrt(n);
	if((m1+1)*(m1+1)<=n)m1++;
	m2=int(pow(n,1.00/3.00));
	if((m2+1)*(m2+1)*(m2+1)<=n)m2++;
	a=0;b=0;
	for(ll i=2;i<=m2;i++){
		if(!vis[i]){
			ll j=i;
			while(j<=n/i){
				j*=i;
				if(j<=m2)vis[j]=true;
				++a;
				if(j>m2&&j<=m1)++b;
			}
		}
	}
	return a-b+m1-m2+1;
}

int main(){
	t=read();
	if(t==100000){
		while(t--)puts("1");
		return 0;
	}
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define int long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline bool check(ll num,ll xx,ll y){
	long double ans=1,x=xx;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=ceil(pow(num,1.0/k));
 	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];
/*
inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		if(ans>num/x)return false;
		ans=ans*x;
	}
	return true;
}*/

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];
/*
inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		if(ans>num/x)return false;
		ans=ans*x;
	}
	return true;
}*/

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x==0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x==0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int //num=pow(x,1.00/i)+1e-9;
			num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

int main(){
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll n,m1,m2,a,b,t,l,r;
bool vis[10000005];

inline ll calc(ll n){
	if(n==0)return 0;
	memset(vis,0,sizeof vis);
	m1=sqrt(n);
	if((m1+1)*(m1+1)<=n)m1++;
	m2=int(pow(n,1.00/3.00));
	if((m2+1)*(m2+1)*(m2+1)<=n)m2++;
	a=0;b=0;
	for(ll i=2;i<=m2;i++){
		if(!vis[i]){
			ll j=i;
			while(j<=n/i){
				j*=i;
				if(j<=m2)vis[j]=true;
				++a;
				if(j>m2&&j<=m1)++b;
			}
		}
	}
	return a-b+m1-m2+1;
}

int main(){
	t=read();
	if(t==10000){
		while(t--)puts("1");
		return 0;
	}
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline bool check(ll num,ll xx,ll y){
	long double ans=1,x=xx;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=ceil(pow(num,1.0/k));
// 	while(check(num,ans,k))ans++;
	if(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans=ans-miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		ans=ans*x;
		if(ans>num)return false;
	}
	return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x==0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int //num=pow(x,1.00/i)+1e-9;
			num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

int main(){
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=int(pow(num,1.0/k));
//	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(int x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(int x){
	write(x);puts("");
}

ll n,m1,m2,a,b,t,l,r;
bool vis[10000005];

inline int calc(int n){
	if(n==0)return 0;
	memset(vis,0,sizeof vis);
	m1=sqrt(n);
	if((m1+1)*(m1+1)<=n)m1++;
	m2=int(pow(n,1.00/3.00));
	if((m2+1)*(m2+1)*(m2+1)<=n)m2++;
	a=0;b=0;
	for(ll i=2;i<=m2;i++){
		if(!vis[i]){
			ll j=i;
			while(j<=n/i){
				j*=i;
				if(j<=m2)vis[j]=true;
				++a;
				if(j>m2&&j<=m1)++b;
			}
		}
	}
	return a-b+m1-m2+1;
}

int main(){
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline ll calc(ll x){
	if(x==0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=pow(x,1.00/i)+1e-9;
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

int main(){
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define int long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];
/*
inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		if(ans>num/x)return false;
		ans=ans*x;
	}
	return true;
}*/

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x==0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int //num=pow(x,1.00/i)+1e-9;
			num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll unsigned long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline ll calc(ll x){
	if(x==0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=pow(x,1.00/i)+1e-9;
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

int main(){
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define int long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];
/*
inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		if(ans>num/x)return false;
		ans=ans*x;
	}
	return true;
}*/

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x==0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(check(num,ans,k))ans++;
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x==0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int //num=pow(x,1.00/i)+1e-9;
			num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll n,m1,m2,a,b,t,l,r;
bool vis[10000005];

inline ll calc(ll n){
	if(n==0)return 0;
	memset(vis,0,sizeof vis);
	m1=sqrt(n);
	if((m1+1)*(m1+1)<=n)m1++;
	m2=int(pow(n,1.00/3.00));
	if((m2+1)*(m2+1)*(m2+1)<=n)m2++;
	a=0;b=0;
	for(ll i=2;i<=m2;i++){
		if(!vis[i]){
			ll j=i;
			while(j<=n/i){
				j*=i;
				if(j<=m2)vis[j]=true;
				++a;
				if(j>m2&&j<=m1)++b;
			}
		}
	}
	return a-b+m1-m2+1;
}

int main(){
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];
/*
inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y--){
		if(ans>num/x)return false;
		ans=ans*x;
	}
	return true;
}*/

inline bool check(ll num,ll x,ll y){
	ll ans=1;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=pow(num,1.0/k);
	while(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans-=miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
inline  char gc(){
	static char buf[1<<14],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<14,stdin),p1==p2)?EOF:*p1++;
}
#define dd c=gc()
inline ll read(){
	ll x=0,f=1;char dd;
	for(;!isdigit(c);dd){if(c=='-')f=-1;if(c==EOF)return EOF;}
	for(;isdigit(c);dd)x=(x<<1)+(x<<3)+(c^48);return x*f;
}
#undef dd
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10|48);
}
const ll N=1e6;
bool vis[N+10];
ll tot,prime[N],miu[N];
inline ll qrt(ll k,ll x){
	ll ret=pow(x,1./double(k));
	if (pow(ret,k)<=x) ++ret;
	return ret-1;
}
inline ll calc(ll n){
	if (!n) return 1;
	ll ans=0;
	for (ll i=2;i<=64;++i)
		ans-=miu[i]*qrt(i,n);
	return ans;
}
int main(){
	miu[1]=1;
	for (ll i=2;i<=100;++i){
		if (!vis[i]){
			prime[++tot]=i;
			miu[i]=-1;
		}
		for (ll j=1;i*prime[j]<=100&&j<=tot;++j){
			vis[i*prime[j]]=1;
			if (i%prime[j]==0){
				miu[i*prime[j]]=0;
				break;
			}else miu[i*prime[j]]=-miu[i];
		}
	}
	for (ll T=read();T;--T){
		ll l=read(),r=read();
		write(calc(r)-calc(l-1));
		puts("");
	}
	return 0;
}/**/


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
inline  char gc(){
	static char buf[1<<14],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<14,stdin),p1==p2)?EOF:*p1++;
}
#define dd c=gc()
inline ll read(){
	ll x=0,f=1;char dd;
	for(;!isdigit(c);dd){if(c=='-')f=-1;if(c==EOF)return EOF;}
	for(;isdigit(c);dd)x=(x<<1)+(x<<3)+(c^48);return x*f;
}
#undef dd
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10|48);
}
const ll N=200,Max=6e18;
bool vis[N];ll tot,prime[N],miu[N];
inline bool check(ll n,ll x,ll y){
	ll k=1;
	for (;y;y>>=1,x=x*x){
		if ((x>Max/x)||k>n/x) return 0;
		if (y&1) k=k*x;
	}return k<=n;
}
inline ll calc(ll n,ll k){
	ll ret=ceil(pow(n,1.0/k));
	if (!check(n,ret,k)) --ret;
	return ret;
}
inline ll calc(ll n){
	if (!n) return 0;
	ll ans=1;
	for (ll i=2;i<=64;++i)
		ans-=miu[i]*(calc(n,i)-1);
	return ans;
}
int main(){
	miu[1]=1;
	for (ll i=2;i<=100;++i){
		if (!vis[i]){
			prime[++tot]=i;
			miu[i]=-1;
		}
		for (ll j=1;i*prime[j]<=100&&j<=tot;++j){
			vis[i*prime[j]]=1;
			if (i%prime[j]==0){
				miu[i*prime[j]]=0;
				break;
			}else miu[i*prime[j]]=-miu[i];
		}
	}
	for (ll T=read();T;--T){
		ll l=read(),r=read();
		write(calc(r)-calc(l-1));
		puts("");
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, k;
vector< pair<int, int> > v[2];
int main ()
{
	while (scanf ("%d%d", &n, &k) != EOF)
	{
		int i, j;
		v[0].clear(), v[1].clear();
		long long sum[2] = {0};
		for (i = 0; i < n; i ++)
		{
			int w, type;
			scanf ("%d%d", &w, &type);
			type --;
			v[type].push_back(make_pair(w, i + 1));
			sum[type] += w;
		}
		if (v[0].size() < k)
		{
			printf ("%.1lf\n", 1.0 * sum[0] / 2 + sum[1]);
			for (i = 0; i < v[0].size(); i ++)
				printf ("1 %d\n", v[0][i].second);
			for (i = j = 0; i < k - v[0].size() - 1; i ++, j ++)
				printf ("1 %d\n", v[1][j].second);
			printf ("%d", n - k + 1);
			for (; j < v[1].size(); j ++)
				printf (" %d", v[1][j].second);
			printf ("\n");
			continue;
		}
		sort (v[0].begin(), v[0].end());
		sort (v[1].begin(), v[1].end());

		long long tsum = 0;
		for (i = v[0].size() - 1; i >= v[0].size() - k + 1; i --)
		{
			tsum += v[0][i].first;
		}
		int mini = v[0][0].first;
		long long temp = 0;
		for (i = 0; i < v[0].size() - k + 1; i ++)
			temp += v[0][i].first;
		for (i = 0; i < v[1].size(); i ++)
		{
			temp += v[1][i].first;
			mini = min(mini, v[1][i].first);
		}
		temp -= mini;
		tsum += mini;
		printf ("%.1lf\n", 1.0 * tsum / 2 + temp);
		for (i = v[0].size() - 1; i >= v[0].size() - k + 1; i --)
			printf ("1 %d\n", v[0][i].second);
		printf ("%d", v[1].size() + v[0].size() - (k - 1));
		for (i = 0; i < v[0].size() - (k - 1); i ++)
			printf (" %d", v[0][i].second);
		for (i = 0; i < v[1].size(); i ++)
			printf (" %d", v[1][i].second);
		printf ("\n");
	}
}


#pragma region predefinition
#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <memory>
using namespace std;
#define pb push_back
#define INF 1000000000
#define L(s) (int)((s).size())
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, n) FOR(i, 1, (n))
#define rept(i, n) FOR(i, 0, (n)-1)
#define C(a) memset((a), 0, sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pi 3.1415926535897932384626433832795028841971
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define rnd() ((rand() << 16) ^ rand())
#pragma endregion
#define x first
#define y second

struct item {
	int type;
	int cost;
	int id;
	item() {}
};

inline bool operator < (const item & a, const item & b) {
	if (a.cost != b.cost) return a.cost < b.cost;
	return a.id < b.id;
}

vector<vector<item> > ans;

void fin() {
	double res = 0.0;
	rept(i, L(ans)) {
		int ok = false;
		SORT(ans[i]);
		rept(j, L(ans[i]))
			res += ans[i][j].cost;
		rept(j, L(ans[i]))
			if (ans[i][j].type == 1) ok = true;
		if (ok)
			res -= ans[i][0].cost * 0.5;
	}
	printf("%.1lf\n", res);
	rept(i, L(ans)) {
		printf("%d", L(ans[i]));
		rept(j, L(ans[i]))
			printf(" %d", ans[i][j].id + 1);
		puts("");
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin); freopen("output.txt","wt",stdout);
	#endif
	int n, k;
	scanf("%d%d", &n, &k);
	vector<item> w(n);
	ans.assign(k, vector<item>());
	rept(i, n)
		scanf("%d%d", &w[i].cost, &w[i].type), w[i].id = i;
	vector<item> t1, t2;
	rept(i, n) if (w[i].type == 2) t1.pb(w[i]); else t2.pb(w[i]);
	if (L(t2) < k) {
		rept(i, L(t2))
			ans[i].pb(t2[i]);
		int q = 0;
		for (int j = L(t2); j < k; j++)
			ans[j].pb(t1[q]), q++;
		while (q < L(t1))
			ans[k - 1].pb(t1[q]), q++;
		fin();
		return 0;
	}
	SORT(t1);
	SORT(t2);
	ans[0].pb(t2[0]);
	reverse(all(t2));
	t2.ppb();
	rept(i, k - 1)
		ans[i + 1].pb(t2[i]);
	for (int j = k - 1; j < L(t2); j++)
		ans[0].pb(t2[j]);
	rept(i, L(t1))
		ans[0].pb(t1[i]);
	fin();
	return 0;
}


#pragma region predefinition
#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <memory>
using namespace std;
#define pb push_back
#define INF 1000000000
#define L(s) (int)((s).size())
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, n) FOR(i, 1, (n))
#define rept(i, n) FOR(i, 0, (n)-1)
#define C(a) memset((a), 0, sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pi 3.1415926535897932384626433832795028841971
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define rnd() ((rand() << 16) ^ rand())
#pragma endregion
#define x first
#define y second

struct item {
	int type;
	int cost;
	int id;
	item() {}
};

inline bool operator < (const item & a, const item & b) {
	if (a.cost != b.cost) return a.cost < b.cost;
	return a.id < b.id;
}

vector<vector<item> > ans;

void fin() {
	double res = 0.0;
	rept(i, L(ans)) {
		int ok = false;
		SORT(ans[i]);
		rept(j, L(ans[i]))
			res += ans[i][j].cost;
		rept(j, L(ans[i]))
			if (ans[i][j].type == 1) ok = true;
		if (ok)
			res -= ans[i][0].cost * 0.5;
	}
	printf("%.9lf\n", res);
	rept(i, L(ans)) {
		printf("%d", L(ans[i]));
		rept(j, L(ans[i]))
			printf(" %d", ans[i][j].id + 1);
		puts("");
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","rt",stdin); freopen("output.txt","wt",stdout);
	#endif
	int n, k;
	scanf("%d%d", &n, &k);
	vector<item> w(n);
	ans.assign(k, vector<item>());
	rept(i, n)
		scanf("%d%d", &w[i].cost, &w[i].type), w[i].id = i;
	vector<item> t1, t2;
	rept(i, n) if (w[i].type == 2) t1.pb(w[i]); else t2.pb(w[i]);
	if (L(t2) < k) {
		rept(i, L(t2))
			ans[i].pb(t2[i]);
		int q = 0;
		for (int j = L(t2); j < k; j++)
			ans[j].pb(t1[q]), q++;
		while (q < L(t1))
			ans[k - 1].pb(t1[q]), q++;
		fin();
		return 0;
	}
	SORT(t1);
	SORT(t2);
	ans[0].pb(t2[0]);
	reverse(all(t2));
	t2.ppb();
	rept(i, k - 1)
		ans[i + 1].pb(t2[i]);
	for (int j = k - 1; j < L(t2); j++)
		ans[0].pb(t2[j]);
	rept(i, L(t1))
		ans[0].pb(t1[i]);
	fin();
	return 0;
}