import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.AbstractCollection;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.Collection;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author sandeepandey
*/
class Main {
public static void main
(String[] args
) { InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
PrimeGenerator solver = new PrimeGenerator();
int testCount
= Integer.
parseInt(in.
next()); for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
}
class PrimeGenerator {
private static final int MAX_SIZE = 1000000000;
private static final int SQRT_LIMIT
= (int) (Math.
sqrt(MAX_SIZE
*1.0) + 1); private static Long[] primes
= null; private static HashSet<Long> lookUp = new HashSet<Long>();
static {
primes = IntegerUtils.doFastSieve(SQRT_LIMIT);
lookUp.
addAll(Arrays.
asList(primes
)); }
public void solve(int testNumber, InputReader in, OutputWriter out) {
long start = in.readLong();
long end = in.readLong();
if(start== 1) {
start++;
}
if(start > end) {
return;
}
long[] array = new long[(int) (end-start+1)];
for(int i = 0; i < (end-start+1) ; i++) {
array[i] = start+i ;
}
boolean[] fromChoose = doProcess(array);
for(int i = 0; i < fromChoose.length ; i++) {
if(fromChoose[i]) {
out.printLine(array[i]);
}
}
}
private boolean[] doProcess(long[] array) {
boolean[] helper = new boolean[array.length];
long fromCheck = array[array.length-1];
for(int i = 0; i < primes.length && (long)(primes[i] * primes[i]) <= fromCheck ; i++) {
int startPos = getStartPos(array[0],primes[i]);
// System.out.println("startpos ::"+array[startPos]);
if((lookUp.contains(array[startPos]))) {
startPos += primes[i];
// System.out.println("startpos ::"+startPos);
}
for(int j = startPos ; j < array.length ; j+=primes[i]) {
helper[j] = false;
}
}
return helper;
}
private int getStartPos(long start,long prime) {
return (start%prime) == 0 ? 0 : ((int) (prime - start % prime));
}
}
class IntegerUtils {
private static char[] mark = new char[0];
private static List<Long> primes = null;
//------------------------------------------------------------------------
//---------------------------------------------------------------
/**
* This method will compute the prime number under supplied limit.
* @param upTo
* @return
*/
public static Long[] doFastSieve
(int upTo
){ mark=new char[upTo/2/8+1];
primes = new ArrayList<Long>();
for (int i = 3; i*i <=upTo; i += 2)
if ( (mark[i>>4] & (1<<((i>>1)&7))) == 0 )
for (int j = i*i; j <=upTo; j += i<<1) mark[j>>4] |= (1<<((j>>1)&7));
primes.add(2l);
for (int i = 3; i <=upTo; i += 2)
if ( (mark[i>>4]&(1<<((i>>1)&7))) == 0) {
primes.
add(Long.
valueOf(i
)); }
return primes.
toArray(new Long[primes.
size()]); }
}
class InputReader {
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
int c = read();
while (isSpaceChar(c))
c = read();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
}
public OutputWriter
(Writer writer
) { }
public void print
(Object...
objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine
(Object...
objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}