#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int big = 2e9;
const int md = 1e9 + 7;
int n, a[N], l[N], r[N], last[N], q, ll, rr, ans[N];
vector<int> sp[N];
pair<int, int> t[N * 4];
void update(int v, int l, int r, int ps, int vl) {
  if (l == r) {
    t[v].first = vl;
    t[v].second = l;
    return;
  }
  int d = (l + r) >> 1;
  if (ps <= d)
    update(v + v, l, d, ps, vl);
  else
    update(v + v + 1, d + 1, r, ps, vl);
  t[v] = min(t[v + v], t[v + v + 1]);
}
pair<int, int> go(int v, int tl, int tr, int l, int r) {
  if (l > r) return {big, big};
  if (tl == l && tr == r) return t[v];
  int d = (tl + tr) >> 1;
  return min(go(v + v, tl, d, l, min(r, d)),
             go(v + v + 1, d + 1, tr, max(l, d + 1), r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
    sp[r[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (last[a[i]] == 0)
      update(1, 1, n, i, -1);
    else {
      update(1, 1, n, last[a[i]], big);
      update(1, 1, n, i, last[a[i]]);
    }
    last[a[i]] = i;
    rr = i;
    for (int j = 0; j < sp[i].size(); j++) {
      int nm = sp[i][j];
      ll = l[nm];
      pair<int, int> d = go(1, 1, n, ll, rr);
      if (d.first >= ll)
        ans[nm] = 0;
      else
        ans[nm] = a[d.second];
    }
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
  return 0;
}
