Problem: Alice had a permutation p_1, p_2, …, p_n. Unfortunately, the permutation looked very boring, so she decided to change it and choose some non-overlapping subranges of this permutation and reverse them. The cost of reversing a single subrange [l, r] (elements from position l to position r, inclusive) is equal to r - l, and the cost of the operation is the sum of costs of reversing individual subranges. Alice had an integer c in mind, so she only considered operations that cost no more than c.

Then she got really bored, and decided to write down all the permutations that she could possibly obtain by performing exactly one operation on the initial permutation. Of course, Alice is very smart, so she wrote down each obtainable permutation exactly once (no matter in how many ways it can be obtained), and of course the list was sorted lexicographically.

Now Bob would like to ask Alice some questions about her list. Each question is in the following form: what is the i-th number in the j-th permutation that Alice wrote down? Since Alice is too bored to answer these questions, she asked you to help her out.

Input

The first line contains a single integer t (1 ≤ t ≤ 30) — the number of test cases.

The first line of each test case contains three integers n, c, q (1 ≤ n ≤ 3 ⋅ 10^4, 1 ≤ c ≤ 4, 1 ≤ q ≤ 3 ⋅ 10^5) — the length of the permutation, the maximum cost of the operation, and the number of queries.

The next line of each test case contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, p_i ≠ p_j if i ≠ j), describing the initial permutation.

The following q lines describe the queries. Each of them contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ 10^{18}), denoting parameters of this query.

It is guaranteed that the sum of values n over all test cases does not exceed 3 ⋅ 10^5, and the sum of values q over all test cases does not exceed 3 ⋅ 10^5.

Output

For each query output the answer for this query, or -1 if j-th permutation does not exist in her list.

Examples

Input


2
3 1 9
1 2 3
1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3
6 4 4
6 5 4 3 1 2
1 1
3 14
1 59
2 6


Output


1
2
3
1
3
2
2
1
3
1
4
-1
5


Input


1
12 4 2
1 2 3 4 5 6 7 8 9 10 11 12
2 20
2 21


Output


2
2

Note

In the first test case, Alice wrote down the following permutations: [1, 2, 3], [1, 3, 2], [2, 1, 3].

Note that, for a permutation [3, 2, 1] Alice would have to reverse the whole array, and it would cost her 2, which is greater than the specified value c=1. The other two permutations can not be obtained by performing exactly one operation described in the problem statement.

Solution (in CPP):

Solution:
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


void run_case() {
    int N, C, Q;
    cin >> N >> C >> Q;
    vector<int> P(N);

    for (auto &p : P)
        cin >> p;

    vector<vector<array<int64_t, 2>>> range(C + 1, vector<array<int64_t, 2>>(N + 1, {0, 1}));
    vector<vector<int64_t>> dp(C + 1, vector<int64_t>(N + 1, 0));

    for (int c = 0; c <= C; c++)
        dp[c][N] = 1;

    for (int start = N - 1; start >= 0; start--) {
        dp[0][start] = 1;

        for (int c = 1; c <= C; c++)
            for (int take = 1; take <= c + 1 && start + take <= N; take++)
                dp[c][start] += dp[c - (take - 1)][start + take];
    }

    for (int start = N - 1; start >= 0; start--)
        for (int c = 1; c <= C; c++) {
            int64_t range_start = 0, range_end = 0;

            for (int take = 1; take <= c + 1 && start + take <= N; take++) {
                int last = P[start + take - 1];

                if (last < P[start]) {
                    int64_t add = dp[c - (take - 1)][start + take];
                    range_start += add;
                    range_end += add;
                } else if (last == P[start]) {
                    int64_t add = dp[c - (take - 1)][start + take];
                    range_end += add;
                }
            }

            range[c][start] = {range_start, range_end};
        }

    vector<vector<int64_t>> range_start_sum(C + 1, vector<int64_t>(N + 2, 0));

    for (int c = 0; c <= C; c++)
        for (int i = 0; i <= N; i++)
            range_start_sum[c][i + 1] = range_start_sum[c][i] + range[c][i][0];

    for (int q = 0; q < Q; q++) {
        int64_t idx, j;
        cin >> idx >> j;
        idx--; j--;
        int c = C, answer = -1;

        if (j >= dp[C][0]) {
            cout << -1 << '\n';
            continue;
        }

        int start = 0;

        while (start < N) {
            if (range[c][start][0] <= j && j < range[c][start][1]) {
                if (idx == start) {
                    answer = P[idx];
                    goto finish;
                }

                int low = start, high = N;

                while (low < high) {
                    int mid = low + (high - low) / 2;

                    int64_t range_sum = range_start_sum[c][mid] - range_start_sum[c][start];
                    int64_t range_start = range_sum + range[c][mid][0];
                    int64_t range_end = range_sum + range[c][mid][1];

                    if (range_start <= j && j < range_end)
                        low = mid + 1;
                    else
                        high = mid;
                }

                if (start <= idx && idx < low) {
                    answer = P[idx];
                    goto finish;
                }

                j -= range_start_sum[c][low] - range_start_sum[c][start];
                start = low;
            } else {
                vector<pair<int, int>> choices;

                for (int i = start; i <= start + c && i < N; i++)
                    choices.emplace_back(P[i], i);

                sort(choices.begin(), choices.end());

                for (auto &pr : choices) {
                    int i = pr.second;
                    int take = i - start + 1;
                    int64_t add = dp[c - (take - 1)][start + take];

                    if (0 <= j && j < add) {
                        if (start <= idx && idx < start + take) {
                            answer = P[start + (start + take - 1 - idx)];
                            goto finish;
                        }

                        c -= take - 1;
                        start += take;
                        break;
                    }

                    j -= add;
                }
            }
        }

        finish:
        cout << answer << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int tests;
    cin >> tests;

    while (tests-- > 0)
        run_case();
}