#include <bits/stdc++.h>
using namespace std;
long long minimum(long long x, long long y) { return min(x, y); }
long long maximum(long long x, long long y) { return max(x, y); }
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<vector<long long> > > dp(n + 1,
                                         vector<vector<long long> >(n + 1));
  vector<long long> z;
  for (int i = 1; i <= n; i++) {
    z.push_back(a[i]);
    dp[i][i] = z;
  }
  vector<long long> z1;
  z1.push_back(a[1]);
  for (int i = 2; i <= n; i++) {
    z1[0] = maximum(z1[0], a[i]);
    dp[1][i] = z1;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      vector<long long> a1 = dp[i - 1][j - 1];
      vector<long long> a2 = dp[i][j - 1];
      a1.push_back(a[j]);
      long long sum1 = 0;
      long long sum2 = 0;
      for (int k = 0; k < i; k++) {
        sum1 += a1[k];
        sum2 += a2[k];
      }
      if (sum1 > sum2)
        dp[i][j] = a1;
      else if (sum2 > sum1)
        dp[i][j] = a2;
      else {
        int k = 0;
        bool f1 = false;
        bool f2 = false;
        while (k < i) {
          if (a1[k] == a2[k])
            k++;
          else if (a1[k] < a2[k]) {
            f1 = true;
            break;
          } else {
            f2 = true;
            break;
          }
        }
        if (f1)
          dp[i][j] = a1;
        else
          dp[i][j] = a2;
      }
    }
  }
  long long m;
  cin >> m;
  while (m--) {
    long long k, pos;
    cin >> k >> pos;
    cout << dp[k][n][pos - 1] << endl;
  }
}
