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;
const int N = 3e4;
#define ll __int128
    ll dp[N][11][11];
    ll dpsum[N][11];
        vector <pair <int, int> > vec[N][11];
    ll dppref[N][11];
        ll dp2[N][11][11];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, c, q;
        cin >> n >> c >> q;
        vector <int> p(n);
        for(int i = 0; i < n; i++)
        {
            cin >> p[i];
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j <= 10; j++)
            {
                dppref[i][j] = 0;
                dpsum[i][j] = 0;
                for(int c1 = 0; c1 <= 10; c1++)
                {
                    dp[i][j][c1] = 0;
                }
            }
        }
        for(int i = n - 1; i >= 0; i--)
        {
            for(int j = 0; j <= c && i + j < n; j++)
            {
                if(i + j == n - 1)
                {
                    dp[i][j][j] = 1;
                }
                else
                {
                    for(int k = 0; k + j <= c; k++)
                    {
                        dp[i][j + k][j] += dpsum[i + j + 1][k];
                    }
                }
            }
            for(int j = 0; j <= c; j++)
            {
                for(int k = 0; k <= c; k++)
                {
                    dpsum[i][j] += dp[i][j][k];
                }
            }
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j <= c; j++)
            {
                for(int k = 0; k <= c; k++)
                {
                    if(k + i >= n || p[k + i] >= p[i])
                    {
                        continue;
                    }
                    dppref[i][j] += dp[i][j][k];
                }
                if(j != 0)
                {
                    dppref[i][j] += dppref[i][j - 1];
                }
            }
        }
        for(int i = 1; i < n; i++)
        {
            for(int j = 0; j <= c; j++)
            {
                if(i != 0)
                {
                    dppref[i][j] += dppref[i - 1][j];
                }
            }
        }
        for(int i = 0; i < n; i++)
        {
            for(int k = 0; k <= c; k++)
            {
                for(int j = 0; j <= c; j++)
                {
                    dp2[i][j][k] = dp[i][j][k];
                    if(j != 0)
                    {
                        dp2[i][j][k] += dp2[i][j - 1][k];
                    }
                }
            }
        }
        ll dp1[n][11];
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j <= c; j++)
            {
                dp1[i][j] = dp[i][j][0];
                if(j != 0){
                    dp1[i][j] += dp[i][j - 1][0];
                }
            }
        }
        ll sumall = 0;
        for(int j = 0;j <= c; j++)
        {
            sumall += dpsum[0][j];
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j <= c; j++)
            {
                vec[i][j].clear();
                if(j != 0)
                {
                    vec[i][j] = vec[i][j - 1];
                }
                if(j + i < n)
                {
                vec[i][j].push_back({p[i + j], j});
                sort(vec[i][j].begin(), vec[i][j].end());
                }
            }
        }
        while(q--)
        {
            long long cnt;
            int ind;
            cin >> ind >> cnt;
            ind--;
            int ans = -1;
            if(sumall >= cnt)
            {
                int st = 0;
                int call = 0;
                int ost = c;
                while(st != n)
                {
                    if(st != 5)
                    {
               //         cout << st << " " << ost << " " << cnt << "\n";
                    }
                    int l = st - 1, r = n - 1;
                    while(r - l > 1)
                    {
                        int midd = (r + l) / 2;
                        ll t1 = dppref[midd][ost];
                        if(st != 0)
                        {
                            t1 -= dppref[st - 1][ost];
                        }
                        ll t2 = t1 + dp1[midd][ost];
                        if(st != 5)
                        {
                      //  cout << st << " " << midd << " " << t1 << " " << dp1[midd][ost] << "\n";
                        }
                        if(t1 < cnt && t2 >= cnt)
                        {
                            l = midd;
                        }
                        else
                        {
                            r = midd;
                        }
                    }

                    if(l != st - 1)
                    {
                        ll t1 = dppref[l][ost];
                        if(st != 0)
                        {
                            t1 -= dppref[st - 1][ost];
                        }
                        cnt -= t1;
                    }
                    if(ind >= st && ind < l + 1)
                    {
                        ans = p[ind];
                    }
                   // cout << st << " " << vec[st][1].size() << "\n";
                    st = l + 1;
                    for(int i = 0; i < vec[st][ost].size(); i++)
                    {
                        int it = vec[st][ost][i].second;
                        ll val = dp2[st][ost][it];
                        if(val >= cnt)
                        {
                            if(ind >= st && ind <= st + it)
                            {
                                ans = p[st + it - (ind - st)];
                            }
                            ost -= it;
                            st += it + 1;
                            break;
                        }
                        else
                        {
                            cnt -= val;
                        }
                    }
                    call++;
             //       assert(call <= 20);
                    //cout << "\n";
                }
            }
            cout << ans << "\n";
        }
    }
    return 0;
}