#include <bits/stdc++.h>
using namespace std;
int n, m, b, l = 1, r, a[500001], c[500001];
bool f[500001];
struct rua {
  int l, r, id, ans;
} q[500001];
vector<int> d;
inline bool cmp(const rua &x, const rua &y) {
  if (x.l / b < y.l / b) return 1;
  if (x.l / b > y.l / b) return 0;
  return ((x.l / b) & 1) ? x.r < y.r : x.r > y.r;
}
inline bool cmp2(const rua &x, const rua &y) { return x.id < y.id; }
inline void rua(int x) {
  if (c[x] == 1 && !f[x]) d.push_back(x), f[x] = 1;
}
inline void add(int x) { c[a[x]]++, rua(a[x]); }
inline void del(int x) { c[a[x]]--, rua(a[x]); }
int main() {
  d.push_back(0), c[0] = 1;
  scanf("%d", &n);
  b = sqrt(n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    while (l > q[i].l) add(--l);
    while (l < q[i].l) del(l++);
    while (r < q[i].r) add(++r);
    while (r > q[i].r) del(r--);
    while (c[d.back()] != 1) f[d.back()] = 0, d.pop_back();
    q[i].ans = d.back();
  }
  sort(q + 1, q + m + 1, cmp2);
  for (int i = 1; i <= m; i++) printf("%d\n", q[i].ans);
  return 0;
}
