#include<bits/stdc++.h>
using namespace std;
// Input macros
#define MOD_mini 1000007
#define s(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define sl(n) scanf("%lld",&n)
#define sf(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
// Useful constants
#define INF (int)1e9
#define EPS 1e-9
// Useful hardware instructions
#define bitcount __builtin_popcount
#define gcd __gcd
// Useful container manipulation / traversal macros
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
#define all(a) a.begin(), a.end()
#define in(a,b) ( (b).find(a) != (b).end())
#define pb push_back
#define fill(a,v) memset(a, v, sizeof a)
#define sz(a) ((int)(a.size()))
#define mp make_pair
// Some common useful functions
#define maX(a,b) ( (a) > (b) ? (a) : (b))
#define miN(a,b) ( (a) < (b) ? (a) : (b))
#define checkbit(n,b) ( (n >> b) & 1)
#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long> vl;
#include<bits/stdc++.h>
using namespace std;
// Input macros
#define s(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define sl(n) scanf("%lld",&n)
#define sf(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
// Useful constants
#define INF (int)1e9
#define EPS 1e-9
// Useful hardware instructions
#define bitcount __builtin_popcount
#define gcd __gcd
// Useful container manipulation / traversal macros
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
#define all(a) a.begin(), a.end()
#define in(a,b) ( (b).find(a) != (b).end())
#define pb push_back
#define fill(a,v) memset(a, v, sizeof a)
#define sz(a) ((int)(a.size()))
#define mp make_pair
// Some common useful functions
#define maX(a,b) ( (a) > (b) ? (a) : (b))
#define miN(a,b) ( (a) < (b) ? (a) : (b))
#define checkbit(n,b) ( (n >> b) & 1)
#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long> vl;
vector<bool> prime(31623,true);
vector<int> primes_list;
int main()
{
int i,j,t,k;
long a,b,m,n,p;;
for(i=3;i<=31623;i=i+2)
{
if(prime[i])
{
for(j=2*i;j<=31623;j=j+i)
{
if(prime[j])
{
prime[j] = false;
}
}
}
}
primes_list.push_back(2);
for(i=3;i<=31622;i=i+2)
{
if(prime[i])
{
primes_list.push_back(i);
//printf("%d ",i);
}
}
//for(i=0;i<primes_list.size();i++)
//printf("%d ",primes_list[i]);
scanf("%d",&t);
for(k=0;k<t;k++)
{
//printf("1\n");
scanf("%ld %ld",&a,&b);
vector<bool> matrix(100005,true);
n = sqrt((double)b);
//printf("%ld\n",n);
for(i=0;primes_list[i]<=n;i++)
{
p = a/primes_list[i];
m=p*primes_list[i];
if(m==0) m=2*primes_list[i];
else if(m<a) m+=primes_list[i];
//printf("%ld\n",p);
for(;m<=b;m+=primes_list[i])
{
matrix[m-a]= false;
//printf("%ld ",m);
}
}
for(i=0;i<=(b-a);i++)
{
if(matrix[i]&&((i+a)!=1))
printf("%ld\n",i+a);
}
printf("\n");
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKLy8gSW5wdXQgbWFjcm9zCiNkZWZpbmUgTU9EX21pbmkgMTAwMDAwNwojZGVmaW5lIHMobikgICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWQiLCZuKQojZGVmaW5lIHNjKG4pICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWMiLCZuKQojZGVmaW5lIHNsKG4pICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWxsZCIsJm4pCiNkZWZpbmUgc2YobikgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlbGYiLCZuKQojZGVmaW5lIHNzKG4pICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJXMiLG4pCi8vIFVzZWZ1bCBjb25zdGFudHMKI2RlZmluZSBJTkYgICAgICAgICAgICAgICAgICAgICAgICAgKGludCkxZTkKI2RlZmluZSBFUFMgICAgICAgICAgICAgICAgICAgICAgICAgMWUtOQovLyBVc2VmdWwgaGFyZHdhcmUgaW5zdHJ1Y3Rpb25zCiNkZWZpbmUgYml0Y291bnQgICAgICAgICAgICAgICAgICAgIF9fYnVpbHRpbl9wb3Bjb3VudAojZGVmaW5lIGdjZCAgICAgICAgICAgICAgICAgICAgICAgICBfX2djZAovLyBVc2VmdWwgY29udGFpbmVyIG1hbmlwdWxhdGlvbiAvIHRyYXZlcnNhbCBtYWNyb3MKI2RlZmluZSBmb3JhbGwoaSxhLGIpICAgICAgICAgICAgICAgZm9yKGludCBpPWE7aTxiO2krKykKI2RlZmluZSBmb3JlYWNoKHYsIGMpICAgICAgICAgICAgICAgZm9yKCB0eXBlb2YoIChjKS5iZWdpbigpKSB2ID0gKGMpLmJlZ2luKCk7ICB2ICE9IChjKS5lbmQoKTsgKyt2KQojZGVmaW5lIGFsbChhKSAgICAgICAgICAgICAgICAgICAgICBhLmJlZ2luKCksIGEuZW5kKCkKI2RlZmluZSBpbihhLGIpICAgICAgICAgICAgICAgICAgICAgKCAoYikuZmluZChhKSAhPSAoYikuZW5kKCkpCiNkZWZpbmUgcGIgICAgICAgICAgICAgICAgICAgICAgICAgIHB1c2hfYmFjawojZGVmaW5lIGZpbGwoYSx2KSAgICAgICAgICAgICAgICAgICAgbWVtc2V0KGEsIHYsIHNpemVvZiBhKQojZGVmaW5lIHN6KGEpICAgICAgICAgICAgICAgICAgICAgICAoKGludCkoYS5zaXplKCkpKQojZGVmaW5lIG1wICAgICAgICAgICAgICAgICAgICAgICAgICBtYWtlX3BhaXIKLy8gU29tZSBjb21tb24gdXNlZnVsIGZ1bmN0aW9ucwojZGVmaW5lIG1hWChhLGIpICAgICAgICAgICAgICAgICAgICAgKCAoYSkgPiAoYikgPyAoYSkgOiAoYikpCiNkZWZpbmUgbWlOKGEsYikgICAgICAgICAgICAgICAgICAgICAoIChhKSA8IChiKSA/IChhKSA6IChiKSkKI2RlZmluZSBjaGVja2JpdChuLGIpICAgICAgICAgICAgICAgICggKG4gPj4gYikgJiAxKQojZGVmaW5lIERSRVAoYSkgICAgICAgICAgICAgICAgICAgICAgc29ydChhbGwoYSkpOyBhLmVyYXNlKHVuaXF1ZShhbGwoYSkpLGEuZW5kKCkpCiNkZWZpbmUgSU5ERVgoYXJyLGluZCkgICAgICAgICAgICAgICAobG93ZXJfYm91bmQoYWxsKGFyciksaW5kKS1hcnIuYmVnaW4oKSkKCnR5cGVkZWYgcGFpcjxpbnQsaW50PiBpaTsKdHlwZWRlZiB2ZWN0b3I8aW50PiB2aTsKdHlwZWRlZiB2ZWN0b3I8bG9uZz4gdmw7CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci8vIElucHV0IG1hY3JvcwojZGVmaW5lIHMobikgICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWQiLCZuKQojZGVmaW5lIHNjKG4pICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWMiLCZuKQojZGVmaW5lIHNsKG4pICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWxsZCIsJm4pCiNkZWZpbmUgc2YobikgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlbGYiLCZuKQojZGVmaW5lIHNzKG4pICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJXMiLG4pCi8vIFVzZWZ1bCBjb25zdGFudHMKI2RlZmluZSBJTkYgICAgICAgICAgICAgICAgICAgICAgICAgKGludCkxZTkKI2RlZmluZSBFUFMgICAgICAgICAgICAgICAgICAgICAgICAgMWUtOQovLyBVc2VmdWwgaGFyZHdhcmUgaW5zdHJ1Y3Rpb25zCiNkZWZpbmUgYml0Y291bnQgICAgICAgICAgICAgICAgICAgIF9fYnVpbHRpbl9wb3Bjb3VudAojZGVmaW5lIGdjZCAgICAgICAgICAgICAgICAgICAgICAgICBfX2djZAovLyBVc2VmdWwgY29udGFpbmVyIG1hbmlwdWxhdGlvbiAvIHRyYXZlcnNhbCBtYWNyb3MKI2RlZmluZSBmb3JhbGwoaSxhLGIpICAgICAgICAgICAgICAgZm9yKGludCBpPWE7aTxiO2krKykKI2RlZmluZSBmb3JlYWNoKHYsIGMpICAgICAgICAgICAgICAgZm9yKCB0eXBlb2YoIChjKS5iZWdpbigpKSB2ID0gKGMpLmJlZ2luKCk7ICB2ICE9IChjKS5lbmQoKTsgKyt2KQojZGVmaW5lIGFsbChhKSAgICAgICAgICAgICAgICAgICAgICBhLmJlZ2luKCksIGEuZW5kKCkKI2RlZmluZSBpbihhLGIpICAgICAgICAgICAgICAgICAgICAgKCAoYikuZmluZChhKSAhPSAoYikuZW5kKCkpCiNkZWZpbmUgcGIgICAgICAgICAgICAgICAgICAgICAgICAgIHB1c2hfYmFjawojZGVmaW5lIGZpbGwoYSx2KSAgICAgICAgICAgICAgICAgICAgbWVtc2V0KGEsIHYsIHNpemVvZiBhKQojZGVmaW5lIHN6KGEpICAgICAgICAgICAgICAgICAgICAgICAoKGludCkoYS5zaXplKCkpKQojZGVmaW5lIG1wICAgICAgICAgICAgICAgICAgICAgICAgICBtYWtlX3BhaXIKLy8gU29tZSBjb21tb24gdXNlZnVsIGZ1bmN0aW9ucwojZGVmaW5lIG1hWChhLGIpICAgICAgICAgICAgICAgICAgICAgKCAoYSkgPiAoYikgPyAoYSkgOiAoYikpCiNkZWZpbmUgbWlOKGEsYikgICAgICAgICAgICAgICAgICAgICAoIChhKSA8IChiKSA/IChhKSA6IChiKSkKI2RlZmluZSBjaGVja2JpdChuLGIpICAgICAgICAgICAgICAgICggKG4gPj4gYikgJiAxKQojZGVmaW5lIERSRVAoYSkgICAgICAgICAgICAgICAgICAgICAgc29ydChhbGwoYSkpOy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