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>
#pragma GCC optimize("O3")
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-const-variable"
using namespace std;
template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;
  static uint32_t barret;
  static uint32_t kbarret;
  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U &x) {
    value = normalize(x);
  }
  static Type inverse(Type a, Type mod) {
    Type b = mod, x = 0, y = 1;
    while (a != 0) {
      Type t = b / a;
      b -= a * t;
      x -= t * y;
      swap(a, b);
      swap(x, y);
    }
    if (x < 0) x += mod;
    return x;
  }
  template <typename U>
  static Type normalize(const U &x) {
    Type v;
    if ((x >= 0 || -mod() <= x) && x < mod())
      v = static_cast<Type>(x);
    else
      v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }
  const Type &operator()() const { return value; }
  template <typename U>
  explicit operator U() const {
    return static_cast<U>(value);
  }
  constexpr static Type mod() { return T::value; }
  Modular &operator+=(const Modular &other) {
    if ((value += other.value) >= mod()) value -= mod();
    return *this;
  }
  Modular &operator-=(const Modular &other) {
    if ((value -= other.value) < 0) value += mod();
    return *this;
  }
  template <typename U>
  Modular &operator+=(const U &other) {
    return *this += Modular(other);
  }
  template <typename U>
  Modular &operator-=(const U &other) {
    return *this -= Modular(other);
  }
  Modular &operator++() { return *this += 1; }
  Modular &operator--() { return *this -= 1; }
  Modular operator++(int) {
    Modular result(*this);
    *this += 1;
    return result;
  }
  Modular operator--(int) {
    Modular result(*this);
    *this -= 1;
    return result;
  }
  Modular operator-() const { return Modular(-value); }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    value = normalize(static_cast<int64_t>(value) *
                      static_cast<int64_t>(rhs.value));
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) *
                                     rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  Modular &operator/=(const Modular &other) {
    return *this *= Modular(inverse(other.value, mod()));
  }
  template <typename U>
  friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);
  template <typename U>
  friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);
  template <typename U>
  friend std::istream &operator>>(std::istream &stream, Modular<U> &number);

 private:
  Type value;
};
template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
  return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) == rhs;
}
template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}
template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value < rhs.value;
}
template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> power(const Modular<T> &a, const U &b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}
template <typename T>
bool IsZero(const Modular<T> &number) {
  return number() == 0;
}
template <typename T>
string to_string(const Modular<T> &number) {
  return to_string(number());
}
template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
  return stream << number();
}
template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x = nullptr;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}
const int md = 1e9 + 7;
using Mint = Modular<std::integral_constant<int, md>>;
template <>
uint32_t Mint::barret = 0;
template <>
uint32_t Mint::kbarret = 0;
void calc_barret() {
  int k = 0;
  while ((1ll << k) <= md) k++;
  Mint::kbarret = k * 2;
  Mint::barret = (1ll << (2 * k)) / md;
}
long long sqr(long long x) { return x * x; }
int mysqrt(long long x) {
  int l = 0, r = 1e9 + 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (m * (long long)m <= x)
      l = m;
    else
      r = m;
  }
  return l;
}
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rndll(
    chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
int gcdex(int a, int b, int &x, int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  int x1, y1;
  int ret = gcdex(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return ret;
}
void setmin(int &x, int y) { x = min(x, y); }
void setmax(int &x, int y) { x = max(x, y); }
void setmin(long long &x, long long y) { x = min(x, y); }
void setmax(long long &x, long long y) { x = max(x, y); }
const long long llinf = 1e18 + 100;
const int maxn = 2e5 + 100, maxw = 5e6 + 100, inf = 2e9 + 100, sq = 450,
          LG = 20, mod = 1e9 + 933, mod1 = 1e9 + 993;
void upd(long long &x, long long y) {
  x += y;
  x = min(x, llinf);
}
struct Str {
  set<pair<long long, int>> g;
  set<pair<int, int>> t;
  long long tot;
};
void solve() {
  int n, C, zaps;
  cin >> n >> C >> zaps;
  vector<vector<long long>> how(n + 1, vector<long long>(C + 1));
  for (int i = 0; i <= C; i++) how[0][i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= C; j++) {
      upd(how[i][j], how[i - 1][j]);
      for (int k = 1; k <= j; k++)
        if (k + 1 <= i) upd(how[i][j], how[i - k - 1][j - k]);
    }
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<vector<Str>> q(n + 1, vector<Str>(C + 1));
  vector<int> ans(zaps, -2);
  vector<pair<long long, int>> que(zaps);
  for (int i = 0; i < zaps; i++) {
    cin >> que[i].second >> que[i].first;
    que[i].second--;
    if (how[n][C] >= que[i].first) {
      q[0][C].g.insert({que[i].first, i});
      q[0][C].t.insert({que[i].second, i});
    }
  }
  auto add = [&](Str &a, long long t, int i) {
    a.g.insert({t - a.tot, i});
    a.t.insert({que[i].second, i});
  };
  auto merge = [&](Str &a, Str const &b) {
    for (auto [T, i] : b.g) add(a, T + b.tot, i);
  };
  auto chs = [&](Str &a) {
    while (!a.t.empty() && ans[a.t.begin()->second] != -2)
      a.t.erase(a.t.begin());
  };
  auto cl = [&](Str &a) {
    set<pair<long long, int>> o;
    swap(a.g, o);
    set<pair<int, int>> o1;
    swap(a.t, o1);
  };
  for (int it = 0; it < n; it++) {
    for (int cs = 0; cs <= C; cs++) {
      vector<pair<vector<int>, pair<long long, int>>> wow;
      for (int i = 0; i <= cs; i++)
        if (it + i + 1 <= n) {
          vector<int> cur;
          for (int j = 0; j <= i; j++) cur.push_back(a[it + j]);
          reverse(cur.begin(), cur.end());
          wow.push_back({cur, make_pair(how[n - it - i - 1][cs - i], i)});
        }
      sort(wow.begin(), wow.end());
      {
        long long curs = 0;
        for (int i = 0; i < wow.size(); i++) {
          upd(curs, wow[i].second.first);
          wow[i].second.first = curs;
        }
      }
      long long L = -1;
      for (int i = 0; i < wow.size(); i++) {
        long long R = wow[i].second.first;
        if (wow[i].second.second > 0) {
          while (1) {
            auto jt = q[it][cs].g.upper_bound({L - q[it][cs].tot, -1});
            if (jt != q[it][cs].g.end() && jt->first + q[it][cs].tot <= R) {
              long long tm = jt->first + q[it][cs].tot - (L - 1);
              int id = jt->second;
              q[it][cs].g.erase(jt);
              if (ans[id] != -2) {
                continue;
              }
              q[it][cs].t.erase({que[id].second, id});
              int tox = it + wow[i].second.second + 1,
                  toy = cs - wow[i].second.second;
              if (que[id].second < tox) {
                ans[id] = wow[i].first[que[id].second - it];
              } else {
                add(q[tox][toy], tm, id);
              }
            } else {
              break;
            }
          }
        }
        L = wow[i].second.first + 1;
      }
      for (int i = 0; i < wow.size(); i++)
        if (wow[i].second.second == 0) {
          q[it][cs].tot += -(i == 0 ? 0 : wow[i - 1].second.first);
          while (1) {
            chs(q[it][cs]);
            if (!q[it][cs].t.empty()) {
              int id = q[it][cs].t.begin()->second;
              if (que[id].second == it) {
                ans[id] = wow[i].first[0];
                q[it][cs].t.erase(q[it][cs].t.begin());
              } else {
                assert(que[id].second > it);
                break;
              }
            } else {
              break;
            }
          }
          merge(q[it][cs], q[it + 1][cs]);
          swap(q[it][cs], q[it + 1][cs]);
        }
    }
  }
  for (int i = 0; i < zaps; i++) cout << ans[i] + 1 << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  cout << fixed;
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
