- 第一行输入一个正整数 T,代表询问次数 (1 ≤ T ≤ 100000)
- 接下来 T 行,每行输入两个正整数 a,b 表示查询素数个数得范围为 [ a,b ] (1 ≤ a ≤ 10000000,a ≤ b ≤ 10000000)
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define INF 0x3f3f3f
#define fi first
#define se second
#define it iterator
#define ins insert
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define pq priority_queue
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false)
#define gcd __gcd
inline ll lgcd(ll a,ll b){return b == 0? a:lgcd(b, a % b);}
inline int lowbit(int x){return x&(-x);}
#define T int t;scanf("%d",&t);while(t--)
#define Ce cout << endl
#define CE(n) cout << n << endl
#define C(n) cout << n;
#define CY cout << "YES" <<
#define CN cout << "NO" << endl
#define Cy cout << "Yes" << endl
#define Cn cout << "No" << endl
int s[10000010];
void init()
{
mem(s);
ll x = 10000000;
for(ll i = 2; i < sqrt(x); i++){
if(s[i]==0){
ll j = 2;
while(i*j<=x){
s[i*j] = 1;
j++;
}
}
}
for(int i = 2; i <= x; i++){
if(s[i]==1){
s[i] = 0;
}else{
s[i] = 1;
}
}
for(int i = 2; i <= x; i++){
s[i] += s[i-1];
}
}
int main()
{
init();
int t;
scanf("%d", &t);
while(t--){
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", s[b]-s[a-1]);
}
return 0;
}