#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool P[1000007];
vector<ll> segmentedSieve(ll L, ll R){
vector<ll> primesInRange;
for (ll i = 0; i <= R - L + 1; i++)
P[i] = 1;
for (ll i = 2; i <= sqrt(R); i++)
for (ll j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)
P[j - L] = 0;
for (ll i = L; i <= R; i++)
if (P[i - L])
primesInRange.push_back(i);
return primesInRange;
}
int main(){
int t;
cin >> t;
while (t--){
ll L, R;
cin >> L >> R;
int dem = 0;
for (ll x : segmentedSieve(L, R))
cout << x << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKYm9vbCBQWzEwMDAwMDddOwp2ZWN0b3I8bGw+IHNlZ21lbnRlZFNpZXZlKGxsIEwsIGxsIFIpewogICAgdmVjdG9yPGxsPiBwcmltZXNJblJhbmdlOwoKICAgIGZvciAobGwgaSA9IDA7IGkgPD0gUiAtIEwgKyAxOyBpKyspCiAgICAgICAgUFtpXSA9IDE7CgogICAgZm9yIChsbCBpID0gMjsgaSA8PSBzcXJ0KFIpOyBpKyspCiAgICAgICAgZm9yIChsbCBqID0gbWF4KGkgKiBpLCAoTCArIGkgLSAxKSAvIGkgKiBpKTsgaiA8PSBSOyBqICs9IGkpCiAgICAgICAgICAgIFBbaiAtIExdID0gMDsKCiAgICBmb3IgKGxsIGkgPSBMOyBpIDw9IFI7IGkrKykKICAgICAgICBpZiAoUFtpIC0gTF0pCiAgICAgICAgICAgIHByaW1lc0luUmFuZ2UucHVzaF9iYWNrKGkpOwoKICAgIHJldHVybiBwcmltZXNJblJhbmdlOwp9CgppbnQgbWFpbigpewogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pewogICAgICAgIGxsIEwsIFI7CiAgICAgICAgY2luID4+IEwgPj4gUjsKICAgICAgICBpbnQgZGVtID0gMDsKICAgICAgICBmb3IgKGxsIHggOiBzZWdtZW50ZWRTaWV2ZShMLCBSKSkKICAgICAgICAgICAgY291dCA8PCB4IDw8ICJcbiI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==