#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
constexpr int mod = 1e9 + 7;
constexpr int Mod = 998244353;
constexpr int MXN = 500000 + 100;
constexpr ld EPS = 1e-10;
constexpr ll inf = 3 * 1e18;
constexpr int Inf = 15 * 1e8;
const vector<int> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll read() {
  ll u, k = scanf("%lld", &u);
  return u;
}
string reads() {
  string s;
  cin >> s;
  return s;
}
pair<ll, ll> readh(bool g = 0) {
  pair<ll, ll> u;
  int k = scanf("%d %d", &u.first, &u.second);
  if (g) u.first--, u.second--;
  return u;
}
void printh(pair<ll, ll> t) { printf("%lld %lld\n", t.first, t.second); }
bool inarea(pair<ll, ll> t, int h, int w) {
  return 0 <= t.first && t.first < h && 0 <= t.second && t.second < w;
}
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p = mod) {
  ll res = 1;
  x %= p;
  while (n > 0) {
    if (n & 1) res = res * x % p;
    x = x * x % p;
    n >>= 1;
  }
  return res;
}
ll bitcount(ll x) {
  int sum = 0;
  for (int i = 0; i < 60; i++)
    if ((1ll << i) & x) sum++;
  return sum;
}
class BIT {
  int size;
  int dat[500000];

 public:
  BIT() {}
  void init(int n) {
    size = n;
    for (int i = 1; i <= n; i++) dat[i] = 0;
  }
  void add(int i, int x = 1) {
    i++;
    while (i <= size) {
      dat[i] += x;
      i += i & -i;
    }
  }
  int query(int i) {
    i++;
    int sum = 0;
    while (i > 0) {
      sum += dat[i];
      i -= i & -i;
    }
    return sum;
  }
};
BIT bit;
int ans[300000];
signed main() {
  int n = read();
  vector<int> a;
  vector<pair<ll, ll>> b;
  for (int(i) = 0; (i) < (n); (i)++) {
    a.emplace_back(read());
    b.emplace_back(pair<ll, ll>{a[i], i});
  }
  sort((b).begin(), (b).end(), [](pair<ll, ll> x, pair<ll, ll> y) {
    if (x.first != y.first) return x.first < y.first;
    return x.second > y.second;
  });
  int q = read();
  vector<pair<ll, pair<ll, ll>>> query;
  for (int(i) = 0; (i) < (q); (i)++) {
    int u, v;
    cin >> u >> v;
    query.emplace_back(make_pair(u, make_pair(v, i)));
  }
  sort((query).begin(), (query).end(), greater<pair<ll, pair<ll, ll>>>());
  bit.init(n);
  for (int(i) = 0; (i) < (n); (i)++) bit.add(i);
  int t = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    while (t < q && n - i == query[t].first) {
      int ok = n - 1, ng = -1, mid;
      while (abs(ok - ng) > 1) {
        mid = (ok + ng) / 2;
        if (bit.query(mid) >= query[t].second.first)
          ok = mid;
        else
          ng = mid;
      }
      ans[query[t].second.second] = a[ok];
      t++;
    }
    bit.add(b[i].second, -1);
  }
  for (int(i) = 0; (i) < (q); (i)++) cout << ans[i] << endl;
}

### Prompt

Please create a solution in cpp to the following problem:

This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.

You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]:

  * [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list); 
  * [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences. 



Suppose that an additional non-negative integer k (1 ≤ k ≤ n) is given, then the subsequence is called optimal if:

  * it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k; 
  * and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal. 



Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 ≤ t ≤ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example:

  * [10, 20, 20] lexicographically less than [10, 21, 1], 
  * [7, 99, 99] is lexicographically less than [10, 21, 1], 
  * [10, 21, 0] is lexicographically less than [10, 21, 1]. 



You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j.

For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] — it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the length of the sequence a.

The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

The third line contains an integer m (1 ≤ m ≤ 100) — the number of requests.

The following m lines contain pairs of integers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j) — the requests.

Output

Print m integers r_1, r_2, ..., r_m (1 ≤ r_j ≤ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j.

Examples

Input


3
10 20 10
6
1 1
2 1
2 2
3 1
3 2
3 3


Output


20
10
20
10
20
10


Input


7
1 2 1 3 1 2 1
9
2 1
2 2
3 1
3 2
3 3
1 1
7 1
7 7
7 4


Output


2
3
2
3
2
3
1
1
3

Note

In the first example, for a=[10,20,10] the optimal subsequences are: 

  * for k=1: [20], 
  * for k=2: [10,20], 
  * for k=3: [10,20,10]. 

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
constexpr int mod = 1e9 + 7;
constexpr int Mod = 998244353;
constexpr int MXN = 500000 + 100;
constexpr ld EPS = 1e-10;
constexpr ll inf = 3 * 1e18;
constexpr int Inf = 15 * 1e8;
const vector<int> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll read() {
  ll u, k = scanf("%lld", &u);
  return u;
}
string reads() {
  string s;
  cin >> s;
  return s;
}
pair<ll, ll> readh(bool g = 0) {
  pair<ll, ll> u;
  int k = scanf("%d %d", &u.first, &u.second);
  if (g) u.first--, u.second--;
  return u;
}
void printh(pair<ll, ll> t) { printf("%lld %lld\n", t.first, t.second); }
bool inarea(pair<ll, ll> t, int h, int w) {
  return 0 <= t.first && t.first < h && 0 <= t.second && t.second < w;
}
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p = mod) {
  ll res = 1;
  x %= p;
  while (n > 0) {
    if (n & 1) res = res * x % p;
    x = x * x % p;
    n >>= 1;
  }
  return res;
}
ll bitcount(ll x) {
  int sum = 0;
  for (int i = 0; i < 60; i++)
    if ((1ll << i) & x) sum++;
  return sum;
}
class BIT {
  int size;
  int dat[500000];

 public:
  BIT() {}
  void init(int n) {
    size = n;
    for (int i = 1; i <= n; i++) dat[i] = 0;
  }
  void add(int i, int x = 1) {
    i++;
    while (i <= size) {
      dat[i] += x;
      i += i & -i;
    }
  }
  int query(int i) {
    i++;
    int sum = 0;
    while (i > 0) {
      sum += dat[i];
      i -= i & -i;
    }
    return sum;
  }
};
BIT bit;
int ans[300000];
signed main() {
  int n = read();
  vector<int> a;
  vector<pair<ll, ll>> b;
  for (int(i) = 0; (i) < (n); (i)++) {
    a.emplace_back(read());
    b.emplace_back(pair<ll, ll>{a[i], i});
  }
  sort((b).begin(), (b).end(), [](pair<ll, ll> x, pair<ll, ll> y) {
    if (x.first != y.first) return x.first < y.first;
    return x.second > y.second;
  });
  int q = read();
  vector<pair<ll, pair<ll, ll>>> query;
  for (int(i) = 0; (i) < (q); (i)++) {
    int u, v;
    cin >> u >> v;
    query.emplace_back(make_pair(u, make_pair(v, i)));
  }
  sort((query).begin(), (query).end(), greater<pair<ll, pair<ll, ll>>>());
  bit.init(n);
  for (int(i) = 0; (i) < (n); (i)++) bit.add(i);
  int t = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    while (t < q && n - i == query[t].first) {
      int ok = n - 1, ng = -1, mid;
      while (abs(ok - ng) > 1) {
        mid = (ok + ng) / 2;
        if (bit.query(mid) >= query[t].second.first)
          ok = mid;
        else
          ng = mid;
      }
      ans[query[t].second.second] = a[ok];
      t++;
    }
    bit.add(b[i].second, -1);
  }
  for (int(i) = 0; (i) < (q); (i)++) cout << ans[i] << endl;
}

```