#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
int n, sq, nq;
struct qu {
  int l, r, id;
};
qu qs[MAXN];
long long ans[MAXN];
bool qcomp(const qu &a, const qu &b) {
  if (a.l / sq != b.l / sq) return a.l < b.l;
  return (a.l / sq) & 1 ? a.r < b.r : a.r > b.r;
}
int am[MAXN], a[MAXN], b[MAXN];
void add(int pos) {
  if (am[a[pos]] == 1) b[a[pos] / sq]--;
  am[a[pos]]++;
  if (am[a[pos]] == 1) b[a[pos] / sq]++;
}
void remove(int pos) {
  if (am[a[pos]] == 1) b[a[pos] / sq]--;
  am[a[pos]]--;
  if (am[a[pos]] == 1) b[a[pos] / sq]++;
}
int get_ans() {
  for (int i = 0, ThxDem = n / sq + 1; i < ThxDem; ++i)
    if (b[i]) {
      for (int j = i * sq, ThxDem = n; j < ThxDem; ++j)
        if (am[j] == 1) return j;
    }
  return 0;
}
void mos() {
  for (int i = 0, ThxDem = nq; i < ThxDem; ++i) qs[i].id = i;
  sq = sqrt(n);
  sort(qs, qs + nq, qcomp);
  int l = 0, r = 0;
  for (int i = 0, ThxDem = nq; i < ThxDem; ++i) {
    qu q = qs[i];
    while (l > q.l) add(--l);
    while (r < q.r) add(r++);
    while (l < q.l) remove(l++);
    while (r > q.r) remove(--r);
    ans[q.id] = get_ans();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) cin >> a[i];
  cin >> nq;
  for (int i = 0, ThxDem = nq; i < ThxDem; ++i) {
    int l, r;
    cin >> l >> r;
    qs[i] = {l - 1, r, i};
  }
  mos();
  for (int i = 0, ThxDem = nq; i < ThxDem; ++i) cout << ans[i] << "\n";
}
