Happy Numbers

Find the smallest start of K consecutive integers with exactly L numbers that are at most M or prime, or output -1.

Medium5Number theoryPrefix sumSliding windowNo attempts yetTime limit0.5sMemory limit64 MB

Problem

Junhyung and Minhyung play a sequence game. Before the game starts, Minhyung picks three numbers KK, LL, and MM. Junhyung then has to say KK consecutive natural numbers.

Minhyung added one more rule to train Junhyung's mental arithmetic. Among the KK numbers Junhyung says, exactly LL of them must be happy numbers. A happy number is a number that meets at least one of the two conditions below.

  • It is a natural number not greater than MM.
  • It is a prime (a number with exactly 2 divisors).

Junhyung is slow at mental arithmetic, so he plans to work the answer out on a computer in secret. Write a program that answers Minhyung's questions.

Input

The first line contains the number of test cases QQ (1Q1000001 \le Q \le 100\,000).

Each of the next QQ lines contains KK, LL, and MM. (1K,M1501 \le K, M \le 150, 0LK0 \le L \le K)

Output

For each test case, print on one line the smallest of the KK numbers Junhyung says, that is, the starting value of the run of KK consecutive natural numbers. If several starting values satisfy the condition, print the smallest one. If no starting value satisfies the condition, or the smallest one is greater than 10,000,000, print -1.