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 <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 5e4 + 5, M = 5;
int C (int x, int y) {
    if (x < 1) return (y == 0);
    if (x < y) return 0; int s = 1;
    for (int i = 0; i < y; ++i) s *= (x - i);
    for (int i = 2; i <= y; ++i) s /= i;
    return s;
}
int ways (int len, int c) {
    int s = 0;
    for (int i = 0; i <= c; ++i)
        s += C (len - 1, i); return s;
}
int n, c, Q, a[N], L[5], R[5], ll[5][N], rr[5][N], s[5][N * M * 2];
struct node {
    int l, r, w;
    void set (int L, int R, int p) {
        l = L, r = R, w = ways (n - r, p - (r - l));
    }
} q[5][N * M * 2];
int o[10]; int tp;
bool cmp (int x, int y) { return a[x] < a[y]; }
void prework () {
    for (int i = 1; i <= c; ++i)
        L[i] = n * c, R[i] = L[i], q[i][R[i]] = {n, n, 1};
    L[0] = R[0] = 1, q[0][1] = {n, n, 1};
    for (int i = n; i >= 1; --i) {
        ll[0][i] = rr[0][i] = 1;
        for (int j = 1; j <= c; ++j) {
            tp = 0;
            for (int k = 1; k <= j && i + k <= n; ++k) o[++tp] = i + k;
            sort (o + 1, o + tp + 1, cmp);
            for (int k = tp, l = i, r; k >= 1; --k)
                if (a[r = o[k]] < a[l]) --L[j], q[j][L[j]].set (l, r, j);
            for (int k = 1, l = i, r; k <= tp; ++k)
                if (a[r = o[k]] > a[l]) ++R[j], q[j][R[j]].set (l, r, j);
            ll[j][i] = L[j], rr[j][i] = R[j];
        }
    }
    for (int i = 1; i <= c; ++i)
        for (int j = L[i]; j <= R[i]; ++j)
            s[i][j] = s[i][j - 1] + q[i][j].w;
}
int sum (int c, int l, int r) {
    return s[c][r] - s[c][l - 1];
}
node get (int x, int c, int k) {
    int l = ll[c][x], r = rr[c][x], mid, res;
    while (l <= r) {
        mid = l + r >> 1;
        if (sum (c, ll[c][x], mid) >= k) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    return {q[c][res].l, q[c][res].r, sum (c, ll[c][x], res - 1)};
}
signed main() {
    int T; read (T);
    while (T--) {
        read (n), read (c), read (Q);
        for (int i = 1; i <= n; ++i) read (a[i]);
        int x = 0, y = 0, now, cnt, res; prework ();
        while (Q--) {
            read (y), read (x); now = 1, cnt = c, res = a[y];
            if (ways (n, c) < x) { puts ("-1"); continue; }
            while (x && cnt && now <= n) {
                node tmp = get (now, cnt, x);
                if (tmp.l <= y && tmp.r >= y) {
                    res = a[tmp.l + tmp.r - y]; break;
                }
                now = tmp.r + 1, cnt -= (tmp.r - tmp.l), x -= tmp.w;
            }
            printf ("%lld\n", res);
        }
    }
    return 0;
}