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:
/*
Problem : 
Algorithm : 
Status : 
*/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define DEBUG cerr << "Passing Line " << __LINE__<< " in Function [" << __FUNCTION__ << "].\n";
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<class T> inline bool checkMax(T &a,const T &b) {return a < b ? a = b,1 : 0;}
template<typename T, typename...Args> inline void checkMax(T &a,const Args...arg) {checkMax(a,max(arg...));}
template<class T> inline bool checkMin(T &a,const T &b) {return a > b ? a = b,1 : 0;}
template<typename T, typename...Args> inline void checkMin(T &a,const Args...arg) {checkMin(a,min(arg...));}

namespace FastIO{
    const int SIZE = 1 << 21;
    char ch;
    char in[SIZE],*inS = in,*inT = in + SIZE;
    char out[SIZE],*outS = out,*outT = out + SIZE;

    #define flush() fwrite(out,1,outS - out,stdout), outS = out
    #define getchar() (inS == inT && (inT = (inS = in) + fread(in,1,SIZE,stdin),inS == inT) ? EOF : *inS++)
    void putchar(char c) {*outS++ = c; if(outS == outT) flush();}

    struct Flusher {~Flusher() {flush();}} flusher;

    template<typename T> inline void read(T &x){
        static int f; x = 0; f = 1; ch = getchar();
        while(!isdigit(ch)) {if(ch == '-') f = -1; ch = getchar();}
        while(isdigit(ch)) {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} x *= f;
    }

    inline void read(char* s){
        static int len; len = 0; ch = getchar();
        while(ch == '\n' || ch == ' ' || ch == '\0') ch = getchar();
        while(ch != '\n' && ch != ' ' && ch != EOF) s[len++] = ch, ch = getchar(); s[len] = '\0';
    }    

    template<typename T> inline void write(T x){
        if(!x) putchar('0');
        if(x < 0) {x = -x; putchar('-');}
        static int sta[20]; int tot = 0;
        while(x) {sta[tot++] = x % 10; x /= 10;}
        while(tot) putchar(sta[--tot] + 48);
    }

    inline void write(char c) {putchar(c);}
    template<typename T> inline void writeln(T c) {write(c); putchar('\n');}

    template<typename T,typename... Args> inline void read(T &t, Args &...args) {read(t); read(args...);}
}

using FastIO::read;
using FastIO::write;
using FastIO::writeln;

const int INF = 0x3f3f3f3f;
const ll llINF = 1e18;
const int MAXN = 6e4 + 5;
const int MAXC = 5;

int n,C,Q,T;
int cnt[MAXC][MAXN],p[MAXN];
ll comb[MAXN][MAXC],w[MAXC][MAXN * MAXC];

struct Node{
    int l,r; ll w;
    Node(int _l = 0,int _r = 0,ll _w = 0) : l(_l), r(_r), w(_w) {}
};

struct Deque{
    int head,tail;
    Node a[MAXN * MAXC * 2 + 100];

    Node& operator [] (const int &i) {return a[head + i - 1];}

    void push_front(Node u) {a[--head] = u; assert(head >= 1);}
    void push_back(Node u) {a[++tail] = u; assert(tail < MAXN * MAXC * 2 + 100);}
    void clear() {head = MAXN * MAXC + 5, tail = MAXN * MAXC + 4;}
    int size() {return tail - head + 1;}
    Deque() {clear();}
} q[MAXC];

void Init(int n){
    comb[0][0] = 1;
    for(int i = 1;i <= n;i++){
        comb[i][0] = 1;
        for(int j = 1;j <= min(MAXC - 1,i);j++)
            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    }
    for(int i = 0;i <= n;i++){
        for(int j = 1;j < MAXC;j++) comb[i][j] += comb[i][j - 1];
    }
}

ll calc(int n,int c){
    if(n <= 0) return 1;
    assert(n < MAXN);
    return comb[n - 1][c];
}

bool cmp(const Node &x,const Node &y){
    return p[x.r] < p[y.r];
}

Node GetNxt(int c,int pos,ll rk){
    int num = cnt[c][pos];
    int l = num + 1, r = q[c].size(), res = 0;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(w[c][mid] - w[c][num] >= rk) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    assert(res >= 1 && res <= q[c].size());
    return Node(q[c][res].l,q[c][res].r,w[c][res - 1] - w[c][num]);
}

void Solve(){
    read(n,C,Q);
    for(int i = 1;i <= n;i++) read(p[i]);
    for(int c = 1;c <= C;c++){
        q[c].clear(); vector<Node> front,back; 
        for(int i = 1;i <= n;i++) cnt[c][i] = 0;
        q[c].push_back(Node(n,n,1));
        for(int i = n - 1;i >= 1;i--){
            front.clear(); back.clear();
            for(int j = 1;j <= min(c,n - i);j++){
                if(p[i + j] < p[i])
                    front.emplace_back(i,i + j,calc(n - i - j,c - j)), cnt[c][i + 1] += 1;
                else back.emplace_back(i,i + j,calc(n - i - j,c - j));
            }
            sort(front.begin(),front.end(),cmp); reverse(front.begin(),front.end());
            sort(back.begin(),back.end(),cmp);
            for(auto x : front) q[c].push_front(x);
            for(auto x : back) q[c].push_back(x);
        }
        for(int i = 1;i <= n;i++) cnt[c][i] += cnt[c][i - 1];
        assert(q[c].size() <= MAXN * MAXC + 5);
        for(int i = 1, sz = q[c].size();i <= sz;i++)
            w[c][i] = w[c][i - 1] + q[c][i].w;
    }
    while(Q--){
        int pos; ll rk; read(pos,rk);
        if(rk > calc(n,C)) {writeln(-1); continue;}
        int x = 1, c = C; vector<pii> vec; vec.clear();
        while(c && x <= n){
            Node res = GetNxt(c,x,rk);
            assert(res.w < rk);
            rk -= res.w; c -= (res.r - res.l); x = res.r + 1;
            vec.emplace_back(res.l,res.r);
        }
        int flag = 0;
        for(auto pi : vec){
            if(pos >= pi.first && pos <= pi.second){
                writeln(p[pi.second - pos + pi.first]);
                flag = 1; break;
            }
        }
        if(!flag) writeln(p[pos]);
    }
}

int main(){
//    freopen("data.in","r",stdin);
//    freopen("data.out","w",stdout);
    Init(MAXN - 1); read(T); while(T--) Solve();
    return 0;
}