#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 5e5 + 10;
template <class T>
inline bool chkmin(T &A, T B) {
  return B < A ? A = B, 1 : 0;
}
template <class T>
inline bool chkmax(T &A, T B) {
  return A < B ? A = B, 1 : 0;
}
template <const int Maxn, const int Maxm>
struct Link_List {
  int tot, Head[Maxn], Next[Maxm], W[Maxm];
  inline void Add(int first, int second) {
    Next[++tot] = Head[first];
    W[Head[first] = tot] = second;
  }
  inline int operator[](int first) { return W[first]; }
};
Link_List<N, N << 1> E;
struct Segment_Tree {
  pair<int, int> A[N << 2];
  pair<int, int> cmp(pair<int, int> a, pair<int, int> b) {
    return a.first >= b.first ? a : b;
  }
  void Update(int pl, int pr, int p, int k, int t) {
    if (pl == pr) {
      A[p] = make_pair(t, pl);
      return;
    }
    int mid = (pl + pr) >> 1;
    if (k <= mid)
      Update(pl, mid, p << 1, k, t);
    else
      Update(mid + 1, pr, p << 1 | 1, k, t);
    A[p] = cmp(A[p << 1], A[p << 1 | 1]);
  }
  pair<int, int> Query(int pl, int pr, int p, int l, int r) {
    if (pl == l && pr == r) return A[p];
    int mid = (pl + pr) >> 1;
    if (r <= mid)
      return Query(pl, mid, p << 1, l, r);
    else if (mid < l)
      return Query(mid + 1, pr, p << 1 | 1, l, r);
    return cmp(Query(pl, mid, p << 1, l, mid),
               Query(mid + 1, pr, p << 1 | 1, mid + 1, r));
  }
} Tr;
int n, m, A[N], id[N], las[N], ans[N];
pair<int, int> Q[N];
bool cmp(int a, int b) { return Q[a] < Q[b]; }
int main() {
  scanf("%d", &n);
  for (int i = (1), i_end = (n); i <= i_end; ++i) scanf("%d", &A[i]);
  scanf("%d", &m);
  for (int i = (1), i_end = (m); i <= i_end; ++i) {
    id[i] = i;
    scanf("%d%d", &Q[i].first, &Q[i].second);
  }
  sort(id + 1, id + 1 + m, cmp);
  int p = m;
  for (int i = (n), i_end = (1); i >= i_end; --i) {
    if (las[A[i]]) Tr.Update(1, n, 1, las[A[i]], -1);
    Tr.Update(1, n, 1, i, las[A[i]] ? las[A[i]] : n + 1);
    las[A[i]] = i;
    while (p && Q[id[p]].first == i) {
      pair<int, int> res = Tr.Query(1, n, 1, Q[id[p]].first, Q[id[p]].second);
      ans[id[p]] = (res.first <= Q[id[p]].second ? 0 : A[res.second]);
      --p;
    }
  }
  for (int i = (1), i_end = (m); i <= i_end; ++i) printf("%d\n", ans[i]);
  return 0;
}
