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<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define N_ 30100
using namespace std;
using pii = pair<int,int>;
int n, K, Q, w[N_], Tw[N_];
long long D[5][N_], P[N_], U[5][N_], S[5][N_];
void Solve(){
    int i, j, k;
    scanf("%d%d%d",&n,&K,&Q);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
    }
    for(i=0;i<=4;i++){
        for(j=0;j<=n;j++){
            U[i][j]=D[i][j]=S[i][j]=0;
        }
    }
    for(i=0;i<=K;i++)U[i][0]=1;
    for(i=1;i<=n;i++){
        for(j=0;j<=K;j++)U[j][i]=U[j][i-1];
        for(j=1;j<=K && j<i;j++){
            for(k=j;k<=K;k++){
                U[k][i] += U[k-j][i-j-1];
                U[k][i] = U[k][i];
            }
        }
    }
    for(i=1;i<=K;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=i && j+k<=n;k++){
                if(w[j+k] < w[j]){
                    D[i][j] += U[i-k][n-(j+k)];
                    D[i][j] = D[i][j];
                }
            }
        }
    }
    for(i=1;i<=K;i++){
        for(j=1;j<=n;j++){
            S[i][j]=S[i][j-1]+D[i][j];
            //if(j%100==0)printf("%lld\n",U[i][j]);
        }
        //puts("");
    }
    while(Q--){
        int loc;
        long long M;
        scanf("%d%lld",&loc,&M);
        if(M > U[K][n]){
            puts("-1");
            continue;
        }
        int ed = 0, TK = K;
        while(1){

            int bb = ed+1, ee = n, rr = ed;
            while(bb<=ee){
                int m = (bb+ee)>>1;
                long long sm = S[TK][m] - S[TK][ed];
                long long dd = U[TK][n-m];
                if(sm < M && sm + dd >= M){
                    rr = m;
                    bb = m+1;
                }
                else{
                    ee = m-1;
                }
            }

            if(loc <= rr){
                printf("%d\n",w[loc]);
                break;
            }

            M -= (S[TK][rr] - S[TK][ed]);
            int pv = rr+1;

            vector<pii>ZZ;
            for(i=0;i<=TK && pv+i <=n;i++){
                ZZ.push_back({w[pv+i],i});
            }
            sort(ZZ.begin(),ZZ.end());
            int fin = 0;
            for(auto &t : ZZ){
                int l = t.second;
                if(M <= U[TK-l][n-(pv+l)]){
                    for(i=pv;i<=pv+l;i++)Tw[i]=w[i];
                    reverse(Tw+pv,Tw+pv+l+1);
                    if(loc <= pv+l){
                        printf("%d\n",Tw[loc]);
                        fin=1;
                        break;
                    }
                    ed = pv+l;
                    TK-=l;
                    break;
                }
                else M-=U[TK-l][n-(pv+l)];
            }
            if(fin)break;
        }
    }
}
int main(){
    int TC;
    scanf("%d",&TC);
    while(TC--){
        Solve();
    }
}