#include <bits/stdc++.h>
using namespace std;
const int mxN = 5e5 + 45, mod = 1e9 + 7;
const long long inf = 2e18 + 43;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, a[mxN], cnt[mxN], ans[mxN];
pair<int, int> t[4 * mxN];
vector<int> pos[mxN];
vector<pair<int, int> > q[mxN], k[mxN];
void Upd(int pos, pair<int, int> new_val, int v = 1, int lb = 1, int rb = n) {
  if (lb == rb) {
    t[v] = new_val;
    return;
  }
  int md = (lb + rb) >> 1;
  if (pos <= md)
    Upd(pos, new_val, v << 1, lb, md);
  else
    Upd(pos, new_val, v << 1 | 1, md + 1, rb);
  t[v] = max(t[v << 1], t[v << 1 | 1]);
}
pair<int, int> Get(int l, int r, int v = 1, int lb = 1, int rb = n) {
  if (l <= lb && rb <= r) return t[v];
  if (l > rb || r < lb) return {0, 0};
  int md = (lb + rb) >> 1;
  return max(Get(l, r, v << 1, lb, md), Get(l, r, v << 1 | 1, md + 1, rb));
}
int main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i], pos[a[i]].push_back(i);
  int m;
  cin >> m;
  for (int i = 1, l, r; i <= m; ++i) {
    cin >> l >> r;
    q[l].push_back({r, i});
  }
  for (int i = 1; i <= n; ++i) {
    int L, R;
    if (!cnt[a[i]])
      L = 1;
    else
      L = pos[a[i]][cnt[a[i]] - 1] + 1;
    if (cnt[a[i]] == pos[a[i]].size() - 1)
      R = n;
    else
      R = pos[a[i]][cnt[a[i]] + 1] - 1;
    k[L].push_back({i, R});
    ++cnt[a[i]];
  }
  for (int i = 1; i <= n; ++i) {
    for (auto j : k[i]) Upd(j.first, {j.second, j.first});
    for (auto j : q[i]) {
      auto res = Get(i, j.first);
      if (res.first >= j.first) ans[j.second] = a[res.second];
    }
  }
  for (int i = 1; i <= m; ++i) cout << ans[i] << '\n';
  return 0;
}
