Problem: Shridhar wants to generate some prime numbers for his cryptosystem. Help him!
Your task is to generate all prime numbers between two given numbers.


Input

The first line contains t, the number of test cases (less then or equal to 10). 

Followed by t lines which contain two numbers m and n (1 ≤ m ≤ n ≤ 1000000000, n-m ≤ 100000) separated by a space.


Output
For every test case print all prime numbers p such that m ≤ p ≤ n,
one number per line.  Separate the answers for each test case by an empty line.

Example
Input:
2
1 10
3 5

Output:
2
3
5
7

3
5

Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)

Solution (in PYTHON):

Solution:
"""Prime Generator


All submissions for this problem are available.

Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers.
Input

The first line contains t, the number of test cases (less then or equal to 10). Followed by t lines which contain two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output

For every test case print all prime numbers p such that m <= p <= n, one number per line. Separate the answers for each test case by an empty line.
Example

Input:
2
1 10
3 5

Output:
2
3
5
7

3
5

Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed) """

import random

def getkq(no):
    x = 0
    while no % 2 == 0:
        x += 1
        no /= 2
    return (x, no)

def primalityTest(no):
    (k, q) = getkq(no-1)
    a = random.randint(2, no - 2)
    # print "no = ", no, "a = ", a
    
    x = pow(a, q, no)
    no -= 1
    if (x == 1) or (x == no) :
        return True
    i = 1
    while i < k :
        x = pow(x, 2, (no+1))
        if x == 1 :
            return False
        if x == no :
            return True
        i += 1
    return False
    
def primeGenerator():
    t = eval(raw_input())
    while t > 0 :
        t -= 1
        (j, end) = (raw_input().split())
        j = eval(j)
        end = eval(end)
        if j == 1 :
            print 2
            j = 3
        if j == 2 :
            print 2
            j = 3
        if j == 3 :
            print 3
            j = 5
        while j <= end:
            # print "j = ", j
            if j % 2 == 0:
                j += 1
                continue
            i = 0
            # print "i at start = ", i
            isPrime = True
            while (i <= 5):
                i += 1
                # print "i = ", i
                if primalityTest(j) == False :
                    isPrime = False
                    break
            if isPrime :
                print j
            j += 1
    
if __name__ == "__main__" :
    # i = 1;
    # while i < 10:
    #     print i
    #     i += 1
    primeGenerator()