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;
static struct FastInput {
  static constexpr int BUF_SIZE = 1 << 20;
  char buf[BUF_SIZE];
  size_t chars_read = 0;
  size_t buf_pos = 0;
  FILE* in = stdin;
  char cur = 0;
  inline char get_char() {
    if (buf_pos >= chars_read) {
      chars_read = fread(buf, 1, BUF_SIZE, in);
      buf_pos = 0;
      buf[0] = (chars_read == 0 ? -1 : buf[0]);
    }
    return cur = buf[buf_pos++];
  }
  inline void tie(int) {}
  inline explicit operator bool() { return cur != -1; }
  inline static bool is_blank(char c) { return c <= ' '; }
  inline bool skip_blanks() {
    while (is_blank(cur) && cur != -1) {
      get_char();
    }
    return cur != -1;
  }
  inline FastInput& operator>>(char& c) {
    skip_blanks();
    c = cur;
    return *this;
  }
  inline FastInput& operator>>(string& s) {
    if (skip_blanks()) {
      s.clear();
      do {
        s += cur;
      } while (!is_blank(get_char()));
    }
    return *this;
  }
  template <typename T>
  inline FastInput& read_integer(T& n) {
    n = 0;
    if (skip_blanks()) {
      int sign = +1;
      if (cur == '-') {
        sign = -1;
        get_char();
      }
      do {
        n += n + (n << 3) + cur - '0';
      } while (!is_blank(get_char()));
      n *= sign;
    }
    return *this;
  }
  template <typename T>
  inline typename enable_if<is_integral<T>::value, FastInput&>::type operator>>(
      T& n) {
    return read_integer(n);
  }
  inline FastInput& operator>>(__int128& n) { return read_integer(n); }
  template <typename T>
  inline typename enable_if<is_floating_point<T>::value, FastInput&>::type
  operator>>(T& n) {
    n = 0;
    if (skip_blanks()) {
      string s;
      (*this) >> s;
      sscanf(s.c_str(), "%lf", &n);
    }
    return *this;
  }
} fast_input;
static struct FastOutput {
  static constexpr int BUF_SIZE = 1 << 20;
  char buf[BUF_SIZE];
  size_t buf_pos = 0;
  static constexpr int TMP_SIZE = 1 << 20;
  char tmp[TMP_SIZE];
  FILE* out = stdout;
  inline void put_char(char c) {
    buf[buf_pos++] = c;
    if (buf_pos == BUF_SIZE) {
      fwrite(buf, 1, buf_pos, out);
      buf_pos = 0;
    }
  }
  ~FastOutput() { fwrite(buf, 1, buf_pos, out); }
  inline FastOutput& operator<<(char c) {
    put_char(c);
    return *this;
  }
  inline FastOutput& operator<<(const char* s) {
    while (*s) {
      put_char(*s++);
    }
    return *this;
  }
  inline FastOutput& operator<<(const string& s) {
    for (int i = 0; i < (int)s.size(); i++) {
      put_char(s[i]);
    }
    return *this;
  }
  template <typename T>
  inline char* integer_to_string(T n) {
    char* p = tmp + TMP_SIZE - 1;
    if (n == 0) {
      *--p = '0';
    } else {
      bool is_negative = false;
      if (n < 0) {
        is_negative = true;
        n = -n;
      }
      while (n > 0) {
        *--p = (char)('0' + n % 10);
        n /= 10;
      }
      if (is_negative) {
        *--p = '-';
      }
    }
    return p;
  }
  template <typename T>
  inline typename enable_if<is_integral<T>::value, char*>::type stringify(T n) {
    return integer_to_string(n);
  }
  inline char* stringify(__int128 n) { return integer_to_string(n); }
  template <typename T>
  inline typename enable_if<is_floating_point<T>::value, char*>::type stringify(
      T n) {
    sprintf(tmp, "%.17f", n);
    return tmp;
  }
  template <typename T>
  inline FastOutput& operator<<(const T& n) {
    auto p = stringify(n);
    for (; *p != 0; p++) {
      put_char(*p);
    }
    return *this;
  }
} fast_output;
const int maxn = 3e4 + 5;
long long comb(long long len, int x) {
  if (len < 0) return 1;
  if (x == 1) return len + 1;
  if (x == 2) return len * (len + 1) / 2 + 1;
  if (x == 3) return len * (len * len + 5) / 6 + 1;
  if (x == 4)
    return len * (len * len * len - len * len * 2 + len * 11 + 14) / 24 + 1;
  return 1;
}
int n, c, q;
int p[maxn];
int siz[maxn];
tuple<int, int, long long> t[5][4 * maxn];
long long sum[5][4 * maxn];
int lcnt[5][maxn];
vector<int> big, sma;
deque<tuple<int, int, long long> > dq[5];
bool smacmp(int a, int b) { return p[a] > p[b]; }
bool bigcmp(int a, int b) { return p[a] < p[b]; }
vector<pair<int, int> > tmp;
void solve(int len, int _c, long long k) {
  if (len <= 0 || _c <= 0) return;
  assert(lcnt[_c][n - len + 1] >= 1);
  int cnt = lower_bound(sum[_c] + lcnt[_c][n - len + 1], sum[_c] + siz[_c] + 1,
                        k + sum[_c][lcnt[_c][n - len + 1] - 1]) -
            sum[_c];
  if (get<0>(t[_c][cnt]) == get<1>(t[_c][cnt])) return;
  tmp.push_back(make_pair(get<0>(t[_c][cnt]), get<1>(t[_c][cnt])));
  solve(n - get<1>(t[_c][cnt]), _c - get<1>(t[_c][cnt]) + get<0>(t[_c][cnt]),
        k - sum[_c][cnt - 1]);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  fast_input.tie(0);
  int start_time = clock();
  int T;
  fast_input >> T;
  while (T--) {
    fast_input >> n >> c >> q;
    for (int i = (0); i <= (c); ++i) dq[i].clear();
    memset(lcnt, -1, sizeof(lcnt));
    for (int i = (1); i <= (n); ++i) fast_input >> p[i];
    for (int i = (0); i <= (c); ++i) dq[i].push_back(make_tuple(n, n, 1));
    for (int x = (n); x >= (1); --x) {
      big.clear(), sma.clear();
      for (int _c = (1); _c <= (min(n - x, c)); ++_c)
        p[x + _c] > p[x] ? big.push_back(x + _c) : sma.push_back(x + _c);
      sort((big).begin(), (big).end(), bigcmp);
      sort((sma).begin(), (sma).end(), smacmp);
      for (auto v : big)
        for (int _c = (1); _c <= (c); ++_c)
          if (v - x <= _c)
            dq[_c].push_back(make_tuple(x, v, comb(n - v - 1, _c - (v - x))));
      for (auto v : sma)
        for (int _c = (1); _c <= (c); ++_c)
          if (v - x <= _c)
            dq[_c].push_front(make_tuple(x, v, comb(n - v - 1, _c - (v - x))));
    }
    memset(siz, 0, sizeof(siz));
    for (int i = (0); i <= (c); ++i) {
      while (!dq[i].empty()) {
        tuple<int, int, long long> u = dq[i].front();
        dq[i].pop_front();
        siz[i]++;
        t[i][siz[i]] = u;
        sum[i][siz[i]] = sum[i][siz[i] - 1] + get<2>(u);
        if (lcnt[i][get<0>(u)] == -1) lcnt[i][get<0>(u)] = siz[i];
      }
      if (i)
        for (int j = (n - 1); j >= (1); --j)
          lcnt[i][j] = min(lcnt[i][j], lcnt[i][j + 1]);
    }
    while (q--) {
      int k;
      long long j;
      fast_input >> k >> j;
      if (j > comb(n - 1, c)) {
        fast_output << -1 << '\n';
        continue;
      }
      tmp.clear();
      solve(n, c, j);
      int ok = 0;
      for (auto v : tmp) {
        if (k >= v.first && k <= v.second) {
          ok = 1;
          fast_output << p[v.first + v.second - k] << '\n';
          break;
        }
      }
      if (!ok) fast_output << p[k] << '\n';
    }
  }
  return 0;
}
