#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
usingnamespace std;
bitset<100000> mybits;
/*
Function print_primes(int x, int y) - prints all the prime nos. between range [x,y].
*/
void print_primes(int a, int b, vector<int> primes)
{
if (b <= primes[primes.size() - 1]) {
// numbers are already precalculated just print them.
for (int i = 0; i < primes.size(); i++) {
if (primes[i] >= a && primes[i] <= b)
cout << primes[i] << endl;
}
return;
}
// use segmented sieve.
mybits.reset();
int limit = (int) sqrt(b);
int temp;
for (int i = a; i <= b; i++) {
if (mybits[i] == 1) goto end;
for (int j = 0; primes[j] <= limit; j++) {
if (i % primes[j] == 0) {
mybits.set(i - a);
temp = i - a + primes[j];
while (1) {
if (temp > b - a) goto end;
mybits.set(temp);
temp = temp + primes[j];
}
}
}
end:
;
}
for (int i = 0; i <= b - a; i++)
if (!mybits.test(i)) cout << i + a << endl;
}
int main()
{
/* Calculate all the primes upto sqrt(10^9) i.e, 31623 using precomputation */
vector<int> primes;
primes.push_back(2);
primes.push_back(3);
int n, a, b;
for (int i = 5; i < 31623; i = i + 2) {
for (int j = 2; j <= sqrt(i); j++) {
if (i % j == 0) {
goto end;
}
}
primes.push_back(i);
end:
;
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
cin >> b;
print_primes(a, b, primes);
cout << endl;
}
return 0;
}