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 <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <functional>
#include <ctime>
#include <sstream>
#include <array>
#include <iomanip>
#include <random>

using namespace std;
typedef long long Long;
typedef long double Double;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Long> VL;
typedef vector<VL> VVL;
typedef pair<int,int> PII;
typedef pair<Long,Long> PLL;

int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(Long &x) { return scanf("%lld", &x); }
int read(Long &x, Long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

#define dlog2(n) ((n) == -1 ? 0 : (31-__builtin_clz(n)))

using namespace std;


template<class T, class U>
struct SegmentTree {
    struct Node {
        bool hasCarry = 0;
        int b = 0,e = 0;
        U carry = U(); T val = T();
        Node(){ }
        void join(const Node &l, const Node &r){
            val = l.val + r.val;
            b = l.b;
            e = r.e;
        }
        void update(const U &u){
            carry += u;
            u(val);
            hasCarry = 1;
        }
        void pushDown(Node &l, Node &r){
            if(!hasCarry)return;
            l.update(carry.trim(0,r.e-r.b+1));
            r.update(carry.trim(l.e-l.b+1,0));
            carry = U();
            hasCarry = 0;
        }
    };
    vector<Node> V;
#define idx(b, e) (((b)+(e))|((b)!=(e))) // memory optimized index
    int N;
    SegmentTree(int N) : V(2*N), N(N){ }
    template<class I>
    void create(const vector<I> &VEC, int b = 0, int e = -1) {
        if(e == -1) e = N-1;
        int n = idx(b, e);
        if (b == e) {
            V[n].val = T(VEC[b]), V[n].b = b, V[n].e = e;
        } else {
            int m = (b + e) / 2;
            create(VEC, b, m);
            create(VEC, m + 1, e);
            V[n].join(V[idx(b, m)], V[idx(m+1, e)]);
        }
    }
    T query(int i, int j, int b = 0, int e = -1) {
        if(e == -1) e = N-1;
        int n = idx(b, e);
        if (i <= b && e <= j){
            return V[n].val;
        } else {
            int m = (b + e) / 2;
            V[n].pushDown(V[idx(b, m)], V[idx(m+1, e)]);
            if (i >  m) return query(i, j, m+1, e);
            if (j <= m) return query(i, j, b, m);
            return query(i, j, b, m) + query(i, j, m+1, e);
        }
    }
    int findOkPrefix(int i, const function<bool(T)> &isOk){
        static int stk[50];
        int ssz = 0;
        stk[ssz++] = (idx(0, N-1));
        T acum; int sz = 0;
        while(ssz > 0) {
            int t = stk[--ssz];
            Node &n = V[t];
            int m = (n.b + n.e) / 2;
            if(n.e < i) continue;
            T newAcum = sz == 0 ? n.val : (acum + n.val);
            if (i <= n.b) {
                if (isOk(newAcum)) {
                    sz += n.e - n.b + 1;
                    acum = newAcum;
                } else {
                    if(n.b == n.e) return sz;
                    n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);
                    stk[ssz++] = (idx(m+1, n.e));
                    stk[ssz++] = (idx(n.b, m));
                }
            } else {
                if(n.b == n.e) continue;
                n.pushDown(V[idx(n.b, m)], V[idx(m+1, n.e)]);
                stk[ssz++] = (idx(m+1, n.e));
                stk[ssz++] = (idx(n.b, m));
            }
        }
        return sz;
    }
    void update(int i, int j, const U &v, int b = 0, int e = -1) {
        if(e == -1) e = N-1;
        int n = idx(b, e);
        if (i <= b && e <= j) {
            V[n].update(v.trim(max(b-i,0), max(j-e,0)));
        } else if (i > e || j < b)
            return;
        else {
            int m = (b + e) / 2;
            int l = idx(b, m), r = idx(m+1, e);
            V[n].pushDown(V[l], V[r]);
            update(i, j, v, b, m);
            update(i, j, v, m + 1, e);
            V[n].join(V[l], V[r]);
        }
    }
};
typedef long long Long;
struct CappedSum {
    Long smF, difLast;
    CappedSum(PLL p = PLL(0, 0)){
        smF = p.first;
        difLast = p.second - p.first;
    }
    CappedSum operator+(const CappedSum &a)const{
        CappedSum r;
        r.smF = min(1LL << 61, smF + a.smF);
        r.difLast = a.difLast;
        return r;
    }
};
struct Void {
    Void(){ }
    Void trim(int l, int r)const{ return *this; }
    void operator+=(const Void &a){ }
    void operator()(CappedSum &a)const{ }
};

Long costOfEach[30010][5][5];
int cat[30010][5];
int GTC = 3;
Long mem[30010][5];
Long dp(int id, int c, const VI &V) {
    int N = V.size();
    if (id == V.size()) return 1;
    if (cat[id][c] == GTC) return mem[id][c];
    VI p;
    for (int t = 0; t <= c && id + t < N; ++t) p.push_back(t);
    sort(p.begin(), p.end(), [&](auto a, auto b) {
        return V[id + a] < V[id + b];
    });
    Long w = 0;
    for (int v : p) {
        costOfEach[id][c][v] = min(w, 1LL<<60);
        w += dp(id + v + 1, c - v, V);
    }
    cat[id][c] = GTC;
    return mem[id][c] = min(w, 1LL<<60);
}

struct Query {
    Long i, j, id;
    bool operator<(const Query &q) const {
        return j != q.j ? j < q.j : id < q.id;
    }
};
struct CmpByI {
    bool operator()(const Query &a, const Query &b) const {
        return a.i != b.i ? a.i < b.i : a.id < b.id;
    }
};
struct VeniceSet {
    set<Query> S;
    set<Query, CmpByI> BI;
    Long sum = 0;
    VeniceSet(set<Query> S) : S(S), BI(S.begin(), S.end()) { }
    int size() { return S.size(); }
    Query last() {
        auto it = S.end(); it--;
        auto r = *it;
        return {r.i, r.j + sum, r.id};
    }
    Query first() {
        auto r = *S.begin();
        return {r.i, r.j + sum, r.id};
    }
    Query firstByI() {
        auto r = *BI.begin();
        return {r.i, r.j + sum, r.id};
    }
    void insert(Query q) {
        S.insert({q.i, q.j - sum, q.id});
        BI.insert({q.i, q.j - sum, q.id});
    }
    void erase(Query q) {
        S.erase({q.i, q.j - sum, q.id});
        BI.erase({q.i, q.j - sum, q.id});
    }
};

VI processAllQueries(int N, int C, int QC, vector<Query> Q) {
    VI ans(QC);
    vector<vector<VeniceSet*>> queue(C + 1, vector<VeniceSet*>(N + 1, NULL));
    queue[C][0] = new VeniceSet(set<Query>(Q.begin(), Q.end()));
    auto addBToA = [](VeniceSet* &a, VeniceSet* &b) {
        if (a == NULL) { swap(a, b); return; }
        if (b == NULL) return;
        if (a->size() < b->size()) swap(a, b);
        while (b->size()) {
            a->insert(b->first());
            b->erase(b->first());
        }
        b = NULL;
    };
    auto releaseAny = [&](VeniceSet* &a, int reverseWindow, int i) {
        while (a->size() > 0 && a->firstByI().i <= i + reverseWindow) {
            auto t = a->firstByI();
            ans[t.id] = i + reverseWindow - (t.i - i);
            a->erase(t);
        }
    };
    for (int id = 0; id < N; ++id) {
        for (int c = 0; c <= C; ++c) {
            auto &cQueue = queue[c][id];
            if (cQueue == NULL || cQueue->size() == 0) continue;
            vector<PLL> T;
            for (int n = 0; n <= c && n + id < N; ++n) {
                T.push_back(PLL(costOfEach[id][c][n], n));
            }
            sort(T.begin(), T.end());
            for (int j = 0; j < T.size(); j++) {
                const auto &n = T[j];
                if (n.second == 0) break;
                VeniceSet* temp = new VeniceSet(set<Query>());
                while (cQueue->size() > 0 && T[j+1].first > cQueue->first().j) {
                    auto q = cQueue->first();
                    cQueue->erase(q);
                    temp->insert(q);
                }
                releaseAny(temp, n.second, id);
                temp->sum += -T[j].first;
                addBToA(queue[c - n.second][id + n.second + 1], temp);
            }
            reverse(T.begin(), T.end());
            for (int j = 0; j < T.size(); j++) {
                const auto &n = T[j];
                if (n.second == 0) break;
                VeniceSet* temp = new VeniceSet(set<Query>());
                while (cQueue->size() > 0 && T[j].first <= cQueue->last().j) {
                    auto q = cQueue->last();
                    cQueue->erase(q);
                    temp->insert(q);
                }
                releaseAny(temp, n.second, id);
                temp->sum += -T[j].first;
                addBToA(queue[c - n.second][id + n.second + 1], temp);
            }
            releaseAny(cQueue, 0, id);
            cQueue->sum += costOfEach[id][c][0];
            addBToA(queue[c][id+1], cQueue);
        }
    }
    return ans;
}

int main() {

    int TC = 1;
    read(TC);
    while (TC-->0) {

        int N, C, Q;
        read(N, C, Q);
        VI V(N);
        int pid = 0;
        for (int &n : V) {
            read(n);
//            n = rand() % 100;
//            n = ++pid;
        }
//        shuffle(V.begin(), V.end(), default_random_engine(rand()));
        GTC++;
        Long mx = dp(0, C, V);
        for (int i = 0; i < N; ++i)
            for (int j = 0; j <= 4; ++j) {
                dp(i, j, V);
            }
        vector<Query> QUERIES;
        VI A(Q);
        for (int i = 0; i < Q; ++i) {
            Long a, b;
//            a = rand() % N + 1;
//            b = rand() % mx + 1;
            read(a, b);
            int c = C;
            int id = 0;
            a--;
            b--;
            if (b >= mx) {
                A[i] = -1;
            } else {
                QUERIES.push_back({a, b, i});
            }
        }
        auto solved = processAllQueries(N, C, Q, QUERIES);
        for (auto q : QUERIES) {
            A[ q.id ] = solved[ q.id ];
        }
        for (int i = 0; i < Q; ++i) {
            cout << (A[i] == -1 ? -1 : V[A[i]]) << endl;
        }
    }


}
/*

 1
6 4 0
6 5 4 3 1 2



 */