#include<bits/stdc++.h>
#define ld long double
#define int long long
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
using namespace std;
const int N=1e5+50;
vector<bool>primes(N,0);
vector<int>p;
void sieve(){
for(int i=1;i<=N;i++)
primes[i]=true;
primes[1]=false;
for(int i=2;i*i<=N;i++){
if(primes[i]){
for(int j=i*i;j<N;j+=i){
primes[j]=false;
}
}
}
for(int i=2;i<=N;i++){
if(primes[i])
p.push_back(i*i);
}
}
void solve(){
int n,k;
cin>>n>>k;
int lans=0,rans=0;
int l=0,r=p.size()-1;
while(l<=r){
int mid=(l+r)/2;
if(p[mid]>n){
rans=mid;
r=mid-1;
}else l=mid+1;
}
l=0;r=p.size()-1;
while(l<=r){
int mid=(l+r)/2;
if(p[mid]<=k){
lans=mid+1;
l=mid+1;
}else r=mid-1;
}
cout<<rans<<" "<<max(0ll,rans-lans)<<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
sieve();
int tt=1;
cin>>tt;
while(tt--)
solve();
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBhbGwodikgdi5iZWdpbigpLHYuZW5kKCkKI2RlZmluZSBhbGxyKHYpIHYucmJlZ2luKCksdi5yZW5kKCkKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE49MWU1KzUwOwp2ZWN0b3I8Ym9vbD5wcmltZXMoTiwwKTsKdmVjdG9yPGludD5wOwp2b2lkIHNpZXZlKCl7CiAgICBmb3IoaW50IGk9MTtpPD1OO2krKykKICAgICAgICBwcmltZXNbaV09dHJ1ZTsKICAgIHByaW1lc1sxXT1mYWxzZTsKICAgIGZvcihpbnQgaT0yO2kqaTw9TjtpKyspewogICAgICAgIGlmKHByaW1lc1tpXSl7CiAgICAgICAgICAgIGZvcihpbnQgaj1pKmk7ajxOO2orPWkpewogICAgICAgICAgICAgICAgcHJpbWVzW2pdPWZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTI7aTw9TjtpKyspewogICAgICAgIGlmKHByaW1lc1tpXSkKICAgICAgICAgICAgcC5wdXNoX2JhY2soaSppKTsKICAgIH0KfQp2b2lkIHNvbHZlKCl7CiAgICAgIGludCBuLGs7CiAgICAgY2luPj5uPj5rOwoKCiAgICAgIGludCBsYW5zPTAscmFucz0wOwogICAgICBpbnQgbD0wLHI9cC5zaXplKCktMTsKICAgICAgd2hpbGUobDw9cil7CiAgICAgICAgaW50IG1pZD0obCtyKS8yOwogICAgICAgIGlmKHBbbWlkXT5uKXsKICAgICAgICAgICAgcmFucz1taWQ7CiAgICAgICAgICAgIHI9bWlkLTE7CgogICAgICAgIH1lbHNlIGw9bWlkKzE7CiAgICAgIH0KICAgICAgbD0wO3I9cC5zaXplKCktMTsKICAgICAgIHdoaWxlKGw8PXIpewogICAgICAgIGludCBtaWQ9KGwrcikvMjsKICAgICAgICBpZihwW21pZF08PWspewogICAgICAgICAgICBsYW5zPW1pZCsxOwogICAgICAgICAgICAgbD1taWQrMTsKCiAgICAgICAgfWVsc2Ugcj1taWQtMTsKICAgICAgfQogICAgICBjb3V0PDxyYW5zPDwiICI8PG1heCgwbGwscmFucy1sYW5zKTw8IlxuIjsKCgp9CmludDMyX3QgbWFpbigpewoKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShudWxscHRyKTsKICAgIGNvdXQudGllKG51bGxwdHIpOwogICAgc2lldmUoKTsKICAgIGludCB0dD0xOwogICAgY2luPj50dDsKICAgIHdoaWxlKHR0LS0pCiAgICAgICAgc29sdmUoKTsKfQo=