#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c h, n;
};
template <class c>
rge<c> range(c h, c n) {
  return rge<c>{h, n};
}
template <class c, class F>
struct rgm {
  c h, n;
  F f;
};
template <class c, class F>
rgm<c, F> map_range(c b, c e, F f) {
  return rgm<c, F>{b, e, f};
}
template <class c, class F>
rgm<typename c::const_iterator, F> map_range(const c &x, F f) {
  return map_range(x.begin(), x.end(), f);
}
template <class c>
auto dud(c *r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
  template <class c>
  muu &operator<<(const c &) {
    return *this;
  }
};
const int MN = 1 << 19;
vector<int> tree[MN * 2];
int __next__77xq43[MN];
vector<pair<int, int> > queries[MN];
vector<int> occs[MN];
int ans[MN];
int a[MN];
pair<int, int> ranges[MN];
void put_r(int l, int r, int v, int wh = 1, int lb = 0, int rb = MN) {
  muu() << __FUNCTION__ << "#" << 64 << ": "
        << "["
           "wh"
           ": "
        << (wh)
        << "] "
           "["
           "lb"
           ": "
        << (lb)
        << "] "
           "["
           "rb"
           ": "
        << (rb) << "] ";
  if (l >= rb || r <= lb) return;
  if (l <= lb && r >= rb) {
    muu() << __FUNCTION__ << "#" << 68 << ": "
          << "push_back "
             "["
             "l"
             ": "
          << (l)
          << "] "
             "["
             "r"
             ": "
          << (r)
          << "] "
             "["
             "lb"
             ": "
          << (lb)
          << "] "
             "["
             "rb"
             ": "
          << (rb)
          << "] "
             "["
             "wh"
             ": "
          << (wh)
          << "] "
             "["
             "v"
             ": "
          << (v) << "] ";
    tree[wh].push_back(v);
  } else {
    int s = (lb + rb) >> 1;
    put_r(l, r, v, wh << 1, lb, s);
    put_r(l, r, v, wh << 1 | 1, s, rb);
  }
}
int get(int x) {
  muu() << __FUNCTION__ << "#" << 80 << ": "
        << "["
           "x"
           ": "
        << (x) << "] ";
  int pos = x + MN;
  while (pos > 0) {
    while (!tree[pos].empty()) {
      int c = tree[pos].back();
      if (ranges[c].first <= x && ranges[c].second > x) return c;
      muu() << __FUNCTION__ << "#" << 86 << ": "
            << "["
               "x"
               ": "
            << (x)
            << "] "
               " erase "
               "["
               "ranges"
               "["
               "c"
               ": "
            << (c)
            << "] "
               ": "
            << ranges[c] << "] ";
      tree[pos].pop_back();
    }
    pos /= 2;
  }
  return 0;
}
void put(int l, int r, int v) {
  muu() << __FUNCTION__ << "#" << 94 << ": "
        << "["
           "l"
           ": "
        << (l)
        << "] "
           "["
           "r"
           ": "
        << (r)
        << "] "
           "["
           "v"
           ": "
        << (v) << "] ";
  ranges[v] = make_pair(l, r);
  put_r(l, r, v);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    occs[a[i]].push_back(i);
  }
  for (int i = 0; i < MN; ++i) occs[i].push_back(n + 1);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    queries[l].emplace_back(r, i);
  }
  for (int i = 0; i < MN; ++i)
    for (int j = 0; j < (int)occs[i].size() - 1; ++j) {
      __next__77xq43[occs[i][j]] = occs[i][j + 1];
    }
  for (int i = 0; i < MN; ++i) {
    if (occs[i].size() > 1u) put(occs[i][0], occs[i][1], i);
  }
  __next__77xq43[n + 1] = n + 1;
  for (int i = 1; i <= n; ++i) {
    for (auto q : queries[i]) {
      ans[q.second] = get(q.first);
      muu() << __FUNCTION__ << "#" << 125 << ": "
            << range(a + i, a + q.first + 1)
            << "["
               "ans"
               "["
               "q.second"
               ": "
            << (q.second)
            << "] "
               ": "
            << ans[q.second] << "] ";
    }
    put(__next__77xq43[i], __next__77xq43[__next__77xq43[i]], a[i]);
  }
  for (int i = 0; i < q; ++i) {
    printf("%d\n", ans[i]);
  }
}
