1
10 2 20
8 5 2 4 10 3 9 7 1 6
5 10
3 17
6 31
3 46
10 42
7 19
9 36
7 3
3 13
8 32
10 25
9 34
10 34
6 33
3 9
2 17
4 5
10 44
9 15
5 40
 1
47 1 47
40 45 19 10 44 33 47 12 2 46 16 23 3 14 21 28 31 42 22 18 35 38 24 25 36 32 4 34 5 20 37 39 6 9 1 7 29 8 17 27 30 11 13 41 15 43 26
39 25
41 24
32 30
10 6
30 13
24 35
41 17
31 31
9 44
21 8
43 23
8 5
29 13
8 4
47 20
22 10
37 27
17 39
43 23
14 42
46 19
43 24
30 31
24 35
31 13
31 32
20 9
3 2
20 9
14 7
7 3
21 36
32 30
47 19
11 43
6 2
31 31
26 12
47 20
2 1
40 24
16 40
45 21
36 28
36 28
17 38
30 31
 1
1 1 4
1
1 1
1 2
1 3
1 4
 1
10 1 1
10 4 6 5 7 9 8 1 3 2
6 10

3
2
7
10
6
7
7
7
5
1
6
6
1
9
4
4
4
1
1
3
 27
27
37
16
20
24
11
20
46
35
11
2
34
47
26
24
7
28
11
3
26
13
37
24
37
37
22
10
22
14
47
38
37
43
23
33
20
4
26
19
30
21
43
1
1
42
37
 1
-1
-1
-1
 9

#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;
}
