#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
vector<pair<int, int> > q[500010];
int n, qn, A[500010], pre[500010], lst[500010], Ans[500010];
pair<int, int> T[500010 * 4];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void modify(const int &l, const int &r, const int &id, const int &p,
            const int &x) {
  if (l == r) {
    T[id] = make_pair(x, A[p]);
    return;
  }
  int mid = (l + r) >> 1, ls = id << 1, rs = id << 1 | 1;
  if (p <= mid)
    modify(l, mid, ls, p, x);
  else
    modify(mid + 1, r, rs, p, x);
  if (T[ls].first < T[rs].first)
    T[id] = T[ls];
  else
    T[id] = T[rs];
}
pair<int, int> query(const int &l, const int &r, const int &id, const int &L,
                     const int &R) {
  if (L <= l && r <= R) return T[id];
  int mid = (l + r) >> 1, ls = id << 1, rs = id << 1 | 1;
  pair<int, int> res = make_pair(1e9, 1e9);
  if (L <= mid) res = min(res, query(l, mid, ls, L, R));
  if (R > mid) res = min(res, query(mid + 1, r, rs, L, R));
  return res;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) pre[i] = lst[A[i] = read()], lst[A[i]] = i;
  qn = read();
  for (int i = 1; i <= qn; ++i) {
    int l = read(), r = read();
    q[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; ++i) {
    if (pre[i]) modify(1, n, 1, pre[i], Inf);
    modify(1, n, 1, i, pre[i]);
    for (pair<int, int> x : q[i]) {
      pair<int, int> lest = query(1, n, 1, x.first, i);
      if (lest.first < x.first) Ans[x.second] = lest.second;
    }
  }
  for (int i = 1; i <= qn; ++i) printf("%d\n", Ans[i]);
  return 0;
}
