#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int pre[maxn], las[maxn], a[maxn], ans[maxn];
struct node {
  int x, y;
  bool operator<(const node &b) const { return x < b.x; }
};
node t[maxn << 2];
vector<node> Q[maxn];
void upt(int o, int l, int r, int p, node v) {
  if (l == r) {
    t[o] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    upt(o << 1, l, mid, p, v);
  else
    upt(o << 1 | 1, mid + 1, r, p, v);
  t[o] = min(t[o << 1], t[o << 1 | 1]);
}
node que(int o, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    return t[o];
  }
  int mid = (l + r) >> 1;
  node tmp = (node){0x3f3f3f3f, 0x3f3f3f3f};
  if (x <= mid) tmp = min(tmp, que(o << 1, l, mid, x, y));
  if (y > mid) tmp = min(tmp, que(o << 1 | 1, mid + 1, r, x, y));
  return tmp;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (las[a[i]]) pre[i] = las[a[i]];
    las[a[i]] = i;
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    Q[y].push_back((node){x, i});
  }
  for (int i = 1; i <= n; ++i) {
    if (pre[i]) {
      upt(1, 1, n, pre[i], (node){0x3f3f3f3f, 0x3f3f3f3f});
    }
    upt(1, 1, n, i, (node){pre[i], a[i]});
    for (int j = 0; j < Q[i].size(); ++j) {
      node tmp = que(1, 1, n, Q[i][j].x, i);
      if (tmp.x < Q[i][j].x) {
        ans[Q[i][j].y] = tmp.y;
      }
    }
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  return 0;
}
