exhausted, and chose to record every one of the stages that she might actually acquire by performing precisely one procedure on the underlying change. Obviously, Alice is extremely savvy, so she recorded each realistic change precisely once (regardless of in the number of ways it tends to be acquired), and obviously the rundown was arranged lexicographically.
Correct answer will be upvoted else Multiple Downvoted. Computer science.
she got truly exhausted, and chose to record every one of the stages that she might actually acquire by performing precisely one procedure on the underlying change. Obviously, Alice is extremely savvy, so she recorded each realistic change precisely once (regardless of in the number of ways it tends to be acquired), and obviously the rundown was arranged lexicographically.
Presently Bob might want to pose Alice a few inquiries about her rundown. Each question is in the accompanying structure: what is the I-th number in the j-th change that Alice recorded? Since Alice is too exhausted to even think about addressing these inquiries, she requested that you help her out.
Input
The primary line contains a solitary integer t (1≤t≤30) — the number of experiments.
The primary line of each experiment contains three integers n, c, q (1≤n≤3⋅104, 1≤c≤4, 1≤q≤3⋅105) — the length of the change, the most extreme expense of the activity, and the number of questions.
The following line of each experiment contains n integers p1,p2,… ,pn (1≤pi≤n, pi≠pj if i≠j), depicting the underlying stage.
The accompanying q lines depict the questions. Every one of them contains two integers I and j (1≤i≤n, 1≤j≤1018), signifying boundaries of this question.
It is ensured that the amount of qualities n over all experiments doesn't surpass 3⋅105, and the amount of qualities q over all experiments doesn't surpass 3⋅105.
Output
For each inquiry output the response for this question, or −1 if j-th stage doesn't exist in her rundown.
Step by step
Solved in 4 steps with 1 images