#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ft first
#define sd second
#define fs(i,x,y) for(int i=(x);i<=(y);i++)
#define fj(i,x,y) for(int i=(x);i>=(y);i--)
inline int read(){
int f=1,x=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f*=-1;
ch=getchar();
}
while((ch>='0'&&ch<='9')){
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
int t,l,r;
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
t=read();
while(t--){
l=read(),r=read();
int sumr=sqrt(r),suml=sqrt(l-1);
cout<<sumr-suml<<'\n';
}
return 0;
}