#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, inf = 1e9;
int n, a[N], q, pter_pos[N], pter_ar, ans[N];
vector<int> pos_number[N];
vector<pair<pair<int, int>, int> > query;
struct It {
  pair<int, int> node[N << 2];
  void build_tree(int nd, int left, int right) {
    if (left > right) return;
    if (left == right) {
      node[nd] = pair<int, int>(0, a[left]);
      return;
    }
    int mid = left + right >> 1;
    build_tree(nd << 1, left, mid);
    build_tree(nd << 1 | 1, mid + 1, right);
    node[nd] = min(node[nd << 1], node[nd << 1 | 1]);
  }
  void update(int nd, int left, int right, int pos, int val) {
    if (left > right || pos < left || right < pos) return;
    if (left == right) {
      node[nd].first = val;
      return;
    }
    int mid = left + right >> 1;
    update(nd << 1, left, mid, pos, val);
    update(nd << 1 | 1, mid + 1, right, pos, val);
    node[nd] = min(node[nd << 1], node[nd << 1 | 1]);
  }
  pair<int, int> get(int nd, int left, int right, int l, int r) {
    if (left > right || right < l || r < left) return pair<int, int>(inf, inf);
    if (l <= left && right <= r) return node[nd];
    int mid = left + right >> 1;
    return min(get(nd << 1, left, mid, l, r),
               get(nd << 1 | 1, mid + 1, right, l, r));
  }
} it;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < N; ++i) pos_number[i].push_back(0), pter_pos[i] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pos_number[a[i]].push_back(i);
  }
  cin >> q;
  for (int id = 0; id < q; ++id) {
    int l, r;
    cin >> l >> r;
    query.push_back(pair<pair<int, int>, int>(pair<int, int>(r, l), id));
  }
  sort(query.begin(), query.end());
  it.build_tree(1, 1, n);
  for (auto q : query) {
    int l = q.first.second, r = q.first.first, id = q.second;
    while (pter_ar < r) {
      pter_ar++;
      pter_pos[a[pter_ar]]++;
      it.update(1, 1, n, pos_number[a[pter_ar]][pter_pos[a[pter_ar]] - 1],
                pos_number[a[pter_ar]][pter_pos[a[pter_ar]] - 1]);
      it.update(1, 1, n, pos_number[a[pter_ar]][pter_pos[a[pter_ar]]],
                pos_number[a[pter_ar]][pter_pos[a[pter_ar]] - 1]);
    }
    pair<int, int> temp = it.get(1, 1, n, l, r);
    if (temp.first < l) ans[id] = temp.second;
  }
  for (int i = 0; i < query.size(); ++i) cout << ans[i] << '\n';
  return 0;
}
