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;
inline int read() {
  int 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 * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline void write(int x) {
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
}
inline void writeln(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  putchar('\n');
}
inline long long readll() {
  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 * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static long long sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
}
inline void writellln(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static long long sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  putchar('\n');
}
const int hashMod = 999983;
template <class TYPENAME>
class HashNode {
 public:
  TYPENAME val;
  int key, next;
  HashNode(TYPENAME _val, int _key, int _next)
      : val(_val), key(_key), next(_next) {}
  bool isNull() { return key == -1; }
};
template <class TYPENAME>
class Hash {
 public:
  vector<HashNode<TYPENAME> > nodes;
  vector<int> d;
  int nodeN;
  Hash() {
    nodeN = 0;
    d = vector<int>(hashMod, -1);
  }
  void push(int key, TYPENAME val) {
    nodes.push_back(HashNode<TYPENAME>(val, key, d[key]));
    d[key] = nodeN++;
  }
  HashNode<TYPENAME> find(int key, TYPENAME val) {
    for (int p = d[key]; p != -1; p = nodes[p].next) {
      if (nodes[p].val == val) {
        return nodes[p];
      }
    }
    return HashNode<TYPENAME>(val, -1, -1);
  }
};
int n, c, q;
vector<int> ii;
vector<long long> jj;
vector<int> p;
vector<vector<long long> > ways, wayC;
long long permContained(int l, int r, int cc) {
  if (l == -1) {
    return 1;
  }
  return ways[n - r - 1][cc - (r - l)];
}
bool pSmaller(const pair<int, int> &a, const pair<int, int> &b) {
  return p[a.second] < p[b.second];
}
bool pGreater(const pair<int, int> &a, const pair<int, int> &b) {
  return p[a.second] > p[b.second];
}
class Query {
 public:
  int ii, idx;
  long long jj;
  Query(int _idx, int _ii, long long _jj) : idx(_idx), ii(_ii), jj(_jj) {}
  void print() { printf("Query(idx = %d, ii = %d, jj = %lld) ", idx, ii, jj); }
};
bool cmpQuery(const Query &a, const Query &b) { return a.jj < b.jj; }
void solve() {
  n = read();
  c = read();
  q = read();
  p = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    p[i] = read();
  }
  ii = vector<int>(q);
  jj = vector<long long>(q);
  for (int i = 0; i < q; ++i) {
    ii[i] = read() - 1;
    jj[i] = readll() - 1;
  }
  wayC = vector<vector<long long> >(n);
  for (int i = 0; i < n; ++i) {
    wayC[i] = vector<long long>(c + 1, 0);
    wayC[i][0] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= c; ++j) {
      if (i < j) {
        wayC[i][j] = 0;
      } else {
        wayC[i][j] = wayC[i - 1][j] + wayC[i - 1][j - 1];
      }
    }
  }
  ways = vector<vector<long long> >(n + 1);
  for (int i = 0; i <= n; ++i) {
    ways[i] = vector<long long>(c + 1, 1);
  }
  for (int i = 1; i <= n; ++i) {
    ways[i][0] = wayC[i - 1][0];
    for (int j = 1; j <= c; ++j) {
      ways[i][j] = ways[i][j - 1] + wayC[i - 1][j];
    }
  }
  vector<deque<pair<int, int> > > dq(c + 1);
  for (int cc = 0; cc <= c; ++cc) {
    dq[cc].push_back({-1, -1});
    for (int i = n - 1; i >= 0; --i) {
      vector<pair<int, int> > lft, rgt;
      for (int j = i + 1; j <= i + cc && j < n; ++j) {
        if (p[j] < p[i]) {
          lft.push_back({i, j});
        } else {
          rgt.push_back({i, j});
        }
      }
      sort(lft.begin(), lft.end(), pGreater);
      sort(rgt.begin(), rgt.end(), pSmaller);
      for (int i = 0; i < lft.size(); ++i) {
        dq[cc].push_front(lft[i]);
      }
      for (int i = 0; i < rgt.size(); ++i) {
        dq[cc].push_back(rgt[i]);
      }
    }
  }
  vector<int> ans(q, -1);
  vector<vector<Query> > que(c + 1);
  for (int i = 0; i < q; ++i) {
    que[c].push_back(Query(i, ii[i], jj[i]));
  }
  vector<vector<long long> > pp(c + 1);
  for (int cc = 0; cc <= c; ++cc) {
    pp[cc] = vector<long long>(n, -1);
    long long perms = 0;
    int ll, rr;
    for (pair<int, int> pr : dq[cc]) {
      ll = pr.first;
      rr = pr.second;
      if (pp[cc][ll] == -1) {
        pp[cc][ll] = perms;
      }
      perms += permContained(ll, rr, cc);
    }
    pp[cc][n - 1] = perms - 1;
    for (int i = n - 2; i >= 0; --i) {
      pp[cc][i] = min(pp[cc][i], pp[cc][i + 1]);
    }
    for (int i = 0; i < n; ++i) {
    }
  }
  for (int cc = c; cc >= 0; --cc) {
    sort(que[cc].begin(), que[cc].end(), cmpQuery);
    int qcur = 0;
    long long currPerm = 0;
    for (int i = 0; i < que[cc].size(); ++i) {
    }
    for (pair<int, int> pr : dq[cc]) {
      int ll = pr.first, rr = pr.second;
      long long newPerm = permContained(ll, rr, cc);
      while (qcur < que[cc].size() && que[cc][qcur].jj < currPerm + newPerm) {
        int cii = que[cc][qcur].ii;
        long long cjj = que[cc][qcur].jj;
        int cidx = que[cc][qcur].idx;
        if (ll == -1 || cii < ll) {
          ans[cidx] = p[cii];
          ++qcur;
          continue;
        }
        if (cii >= ll && cii <= rr) {
          ans[cidx] = p[rr - (cii - ll)];
          ++qcur;
          continue;
        }
        int nc = cc - (rr - ll);
        if (rr >= n - 1) {
          ans[cidx] = -1;
          ++qcur;
          continue;
        }
        que[nc].push_back(Query(cidx, cii, pp[nc][rr + 1] + cjj - currPerm));
        ++qcur;
      }
      currPerm += newPerm;
    }
  }
  for (int i = 0; i < q; ++i) {
    writeln(ans[i]);
  }
}
int main() {
  int t = read();
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
