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>
const long long maxn = 3e4 + 9, maxc = 5;
long long Read() {
  long long x(0), f(1);
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3ll) + (x << 1ll) + c - '0';
    c = getchar();
  }
  return x * f;
}
long long T, n, C, q;
long long p[maxn], dl[maxn], dr[maxn], sumw[maxc][(maxn * maxc << 1) + 10];
std::pair<long long, long long> range[maxc][(maxn * maxc << 1) + 10];
struct node {
  long long l, r, w;
  bool operator<(const node A) const { return p[r] < p[A.r]; }
};
node L[maxc][(maxn * maxc << 1) + 10];
long long Comb(long long N, long long M) {
  long long ret(1);
  for (long long i = 1; i <= M; ++i) ret *= (N - i + 1);
  for (long long i = 1; i <= M; ++i) ret /= i;
  return ret;
}
long long Way(long long len, long long c) {
  long long ret(0);
  for (long long i = 0; i <= c; ++i) ret += Comb(len - 1, i);
  return ret;
}
node F(long long i, long long c, long long w) {
  long long l(range[c][i].first), r(range[c][i].second), nw(l - 1);
  long long v(sumw[c][range[c][i].first - 1]);
  while (l <= r) {
    long long mid(l + r >> 1);
    if (sumw[c][mid] - v < w) {
      nw = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  node tmp(L[c][nw + 1]);
  tmp.w = sumw[c][nw] - v;
  return tmp;
}
void Init() {
  for (long long c = 0; c <= C; ++c) {
    dl[c] = maxn * maxc + 5;
    dr[c] = maxn * maxc + 4;
    L[c][++dr[c]] = (node){n, n, 1};
    range[c][n] = std::pair<long long, long long>(dl[c], dr[c]);
    for (long long i = n - 1; i >= 1; --i) {
      long long _l(0), _r(0);
      for (long long len = 1; len <= std::min(c, n - i); ++len) {
        long long j(i + len);
        if (p[j] < p[i]) {
          ++_l;
          L[c][dl[c] - _l] = (node){i, j, Way(n - j, c - len)};
        } else {
          ++_r;
          L[c][dr[c] + _r] = (node){i, j, Way(n - j, c - len)};
        }
      }
      if (_l) {
        std::sort(L[c] + dl[c] - _l, L[c] + dl[c]);
        dl[c] -= _l;
      }
      if (_r) {
        std::sort(L[c] + dr[c] + 1, L[c] + dr[c] + _r + 1);
        dr[c] += _r;
      }
      range[c][i] = std::pair<long long, long long>(dl[c], dr[c]);
    }
    sumw[c][dl[c] - 1] = 0;
    for (long long i = dl[c]; i <= dr[c]; ++i) {
      sumw[c][i] = sumw[c][i - 1] + L[c][i].w;
    }
  }
}
int main() {
  T = Read();
  while (T--) {
    n = Read();
    C = Read();
    q = Read();
    for (long long i = 1; i <= n; ++i) p[i] = Read();
    Init();
    while (q--) {
      long long pos1(Read()), pos2(Read());
      if (pos2 > sumw[C][dr[C]]) {
        puts("-1");
        continue;
      }
      long long pos(1);
      long long c(C);
      std::vector<node> suq;
      while (true) {
        node tmp(F(pos, c, pos2));
        suq.push_back(tmp);
        pos2 -= tmp.w;
        c -= tmp.r - tmp.l;
        pos = tmp.r + 1;
        if (pos > n || !pos2) break;
      }
      long long flag(0);
      for (long long i = 0; i < suq.size(); ++i) {
        long long l(suq[i].l), r(suq[i].r);
        if (l <= pos1 && pos1 <= r) {
          printf("%lld\n", p[r - (pos1 - l)]);
          flag = 1;
          break;
        }
      }
      if (!flag) {
        printf("%lld\n", p[pos1]);
      }
    }
  }
}
