Curiosity

For each query [a, b], find the primes in the range in order and compute an alternating sum that triples odd-indexed primes.

Medium5Number theoryPrefix sumMathBrute forceNo attempts yetTime limit1sMemory limit128 MB

Problem

Namgyu is a curious person. He built a function FF that takes two integers aa and bb and computes a value from the primes that lie between them.

Let the primes inside the closed interval [a,b][a, b], listed from smallest to largest, be A1<A2<<AnA_1 < A_2 < \dots < A_n. The function F(a,b)F(a, b) multiplies every odd numbered prime by 3 and adds it, then subtracts every even numbered prime as it is.

F(a,b)=3A1A2+3A3A4+3A5A6+F(a, b) = 3A_1 - A_2 + 3A_3 - A_4 + 3A_5 - A_6 + \dots

The count nn decides the sign of the last term. If nn is odd the sum ends with +3An+3A_n, and if nn is even it ends with An-A_n.

For example, consider F(3,7)F(3, 7). The primes from 3 to 7 inclusive are 3, 5, and 7, so the value is 3×35+3×7=253 \times 3 - 5 + 3 \times 7 = 25.

If the interval holds no prime at all, F(a,b)F(a, b) is 0.

Input

The first line contains the number of questions qq. (1q1051 \le q \le 10^5)

Each of the next qq lines holds one question as two integers aa and bb separated by a space. (1ab1051 \le a \le b \le 10^5)

Output

For each question, print the value of F(a,b)F(a, b) on its own line, in the order the questions are given.