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 m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 300005;

int n, c, q;
int p[N];
int x[N];

vector<pair<int, int> > ans[N];

vector<pair<ll, int> > v[5];
vector<int> vv[5];

ll ways(int n, int c)
{
    if (n == 0)
        return 1;
    ll ans = 0;
    ll yans = 1;
    ans += yans;
    for (int i = n - 1; i >= n - c; --i)
    {
        yans *= i;
        yans /= ((n - 1) - i + 1);
        ans += yans;
    }
    return ans;
}

ll pp[N];
void solv()
{
    cin >> n >> c >> q;

    for (int i = 1; i <= n; ++i)
        ans[i].clear();
    for (int i = 0; i <= c; ++i)
    {
        v[i].clear();
        vv[i].clear();
    }

    for (int i = 1; i <= n; ++i)
        cin >> p[i];
    for (int i = 1; i <= q; ++i)
    {
        ll y;
        cin >> x[i] >> y;
        if (y > ways(n, c))
            ans[i].push_back(m_p(-1, -1));
        else
            v[c].push_back(m_p(y, i));
    }

    for (int k = c; k >= 0; --k)
    {
        if (k != c)
        {
            for (int i = 1; i <= n; ++i)
            {
                pp[i] = pp[i - 1];
                for (int j = i + 1; j <= n && j - i <= k; ++j)
                {
                    if (p[j] < p[i])
                        pp[i] += ways(n - j, k - (j - i));
                }
            }
            for (int i = 0; i < v[k].size(); ++i)
                v[k][i].fi += pp[vv[k][i]];
        }

        deque<pair<int, int> > q;
        q.push_back(m_p(n, n));
        for (int i = n; i >= 1; --i)
        {
            vector<pair<int, int> > v;
            for (int j = i + 1; j <= n && j - i <= k; ++j)
            {
                v.push_back(m_p(p[j], j));
            }
            sort(all(v));
            for (int j = 0; j < sz(v); ++j)
            {
                if (v[j].fi > p[i])
                    q.push_back(m_p(i, v[j].se));
            }
            for (int j = sz(v) - 1; j >= 0; --j)
            {
                if (v[j].fi < p[i])
                    q.push_front(m_p(i, v[j].se));
            }
        }

        sort(all(v[k]));
        ll u = 0;
        int j = 0;
        for (int i = 0; i < v[k].size(); ++i)
        {
            while (v[k][i].fi > u + ways(n - q[j].se, k - (q[j].se - q[j].fi)))
            {
                u += ways(n - q[j].se, k - (q[j].se - q[j].fi));
                ++j;
            }
            ans[v[k][i].se].push_back(q[j]);
            if (q[j] != m_p(n, n))
            {
                v[k - (q[j].se - q[j].fi)].push_back(m_p(v[k][i].fi - u, v[k][i].se));
                vv[k - (q[j].se - q[j].fi)].push_back(q[j].se);
            }
        }
    }

    for (int i = 1; i <= q; ++i)
    {
        if (!ans[i].empty() && ans[i][0].fi == -1)
        {
            cout << "-1\n";
            continue;
        }
        bool z = false;
        for (int j = 0; j < ans[i].size(); ++j)
        {
            if (ans[i][j].fi <= x[i] && x[i] <= ans[i][j].se)
            {
                cout << p[ans[i][j].se - (x[i] - ans[i][j].fi)] << "\n";
                z = true;
                break;
            }
        }
        if (!z)
            cout << p[x[i]] << "\n";
    }
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);

    int tt = 1;
    cin >> tt;
    while (tt--)
    {
        solv();
    }
    return 0;
}