#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10, inf = 0x3f3f3f3f;
int arr[maxn], pre[maxn], ans[maxn];
pair<int, int> tree[maxn << 2];
struct query {
  int l;
  int r;
  int id;
} q[maxn];
bool cmp(query a, query b) {
  if (a.r == b.r)
    return a.l < b.l;
  else
    return a.r < b.r;
}
inline void PushUp(int rt) { tree[rt] = min(tree[rt << 1], tree[rt << 1 | 1]); }
inline void build(int l, int r, int rt) {
  if (l == r) {
    tree[rt].first = tree[rt].second = inf;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  PushUp(rt);
}
inline void update(int x, int y, int l, int r, int rt) {
  if (l == r) {
    tree[rt] = make_pair(y, x);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, y, l, mid, rt << 1);
  else
    update(x, y, mid + 1, r, rt << 1 | 1);
  PushUp(rt);
}
inline pair<int, int> query(int i, int j, int l, int r, int rt) {
  if (i <= l && r <= j) {
    return tree[rt];
  }
  int mid = (l + r) >> 1;
  pair<int, int> ret = make_pair(inf, inf);
  if (i <= mid) ret = min(ret, query(i, j, l, mid, rt << 1));
  if (j > mid) ret = min(ret, query(i, j, mid + 1, r, rt << 1 | 1));
  return ret;
}
inline int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    arr[i] = read();
  }
  build(1, n, 1);
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    q[i].l = read();
    q[i].r = read();
    q[i].id = i;
  }
  sort(q + 1, q + 1 + Q, cmp);
  int pos = 0;
  for (int i = 1; i <= Q; i++) {
    while (pos < q[i].r) {
      ++pos;
      update(pos, pre[arr[pos]], 1, n, 1);
      if (pre[arr[pos]]) update(pre[arr[pos]], inf, 1, n, 1);
      pre[arr[pos]] = pos;
    }
    pair<int, int> tmp = query(q[i].l, q[i].r, 1, n, 1);
    if (tmp.first < q[i].l) ans[q[i].id] = arr[tmp.second];
  }
  for (int i = 1; i <= Q; i++) cout << ans[i] << endl;
}
