#include <bits/stdc++.h>
using namespace std;
const int N = 500500;
int n, q, a[N], nxt[N], pos[N], ans[N];
struct S {
  int f = 0, s = 0;
} tr[N * 4];
vector<pair<int, int> > v[N];
void up(int d, int l, int r, int i, int v, int j) {
  if (i < l || i > r) return;
  if (l == r)
    tr[d].f = v, tr[d].s = j;
  else {
    int m = (l + r) / 2;
    up(d * 2, l, m, i, v, j);
    up(d * 2 + 1, m + 1, r, i, v, j);
    if (tr[d * 2 + 1].f > tr[d * 2].f)
      tr[d] = tr[d * 2 + 1];
    else
      tr[d] = tr[d * 2];
  }
}
S get(int d, int l, int r, int f, int t) {
  if (r < f || t < l) {
    S Z;
    Z.f = -1, Z.s = -1;
    return Z;
  }
  if (f <= l && r <= t) return tr[d];
  int m = (l + r) / 2;
  S A = get(d * 2, l, m, f, t);
  S B = get(d * 2 + 1, m + 1, r, f, t);
  return (A.f > B.f) ? A : B;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  scanf("%d", &q);
  for (int i = 1, l, r; i <= q; i++) {
    cin >> l >> r;
    v[l].push_back(make_pair(r, i));
  }
  for (int i = 1; i < N; i++) pos[i] = 1e9;
  for (int i = n; i > 0; i--) {
    nxt[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  for (int i = 0; i < 4 * N; i++) tr[i].f = -1, tr[i].s = -1;
  for (int i = n; i > 0; i--) {
    if (nxt[i] <= n) up(1, 1, n, nxt[i], -1, -1);
    up(1, 1, n, i, nxt[i], a[i]);
    for (auto u : v[i]) {
      S x = get(1, 1, n, i, u.first);
      if (x.f > u.first) {
        if (x.s != -1) ans[u.second] = x.s;
      }
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
