Under construction

Still being built. Things may change

Happy Numbers

Time limit0.5sMemory limit64 MB

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

Medium5 of 10

Topics
Number theory, Prefix sum, Sliding window
Solved
No attempts yet

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 (1≤Q≤100 0001 \le Q \le 100\,000).

Each of the next QQ lines contains KK, LL, and MM. (1≤K,M≤1501 \le K, M \le 150, 0≤L≤K0 \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.

Examples3

  1. Example 1

    Input
    3
    1 1 1
    2 0 2
    3 1 1
    
    Expected output
    1
    8
    4
    
  2. Example 2

    Input
    3
    4 1 1
    5 2 3
    5 0 3
    
    Expected output
    6
    4
    24
    
  3. Example 3

    Input
    4
    7 2 5
    6 1 1
    10 4 5
    6 2 2
    
    Expected output
    6
    20
    5
    4