#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A>
ostream& operator<<(ostream& cout, vector<A> const& v);
template <typename A, typename B>
ostream& operator<<(ostream& cout, pair<A, B> const& p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream& operator<<(ostream& cout, vector<A> const& v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
#pragma message("be careful, freopen may be wrong")
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
const long double pi = 3.14159265358979323846;
const long long mod = 1000000007;
template <typename num_t>
struct segtree {
  int n, depth;
  vector<num_t> tree, lazy;
  void init(int second, long long* arr) {
    n = second;
    tree = vector<num_t>(6 * second, 0);
    lazy = vector<num_t>(6 * second, 0);
    init(0, 0, n - 1, arr);
  }
  num_t init(int i, int l, int r, long long* arr) {
    if (l == r) return tree[i] = num_t(arr[l], l);
    int mid = (l + r) / 2;
    num_t a = init(2 * i + 1, l, mid, arr),
          b = init(2 * i + 2, mid + 1, r, arr);
    return tree[i] = a.op(b);
  }
  void update(int l, int r, num_t v) { update(0, 0, n - 1, l, r, v); }
  num_t update(int i, int tl, int tr, int ql, int qr, num_t v) {
    eval_lazy(i, tl, tr);
    if (ql <= tl && tr <= qr) {
      lazy[i] = lazy[i].val + v.val;
      eval_lazy(i, tl, tr);
      return tree[i];
    }
    if (tl > tr || tr < ql || qr < tl) return tree[i];
    if (tl == tr) return tree[i];
    int mid = (tl + tr) / 2;
    num_t a = update(2 * i + 1, tl, mid, ql, qr, v),
          b = update(2 * i + 2, mid + 1, tr, ql, qr, v);
    return tree[i] = a.op(b);
  }
  num_t query(int l, int r) { return query(0, 0, n - 1, l, r); }
  num_t query(int i, int tl, int tr, int ql, int qr) {
    eval_lazy(i, tl, tr);
    if (ql <= tl && tr <= qr) return tree[i];
    if (tl > tr || tr < ql || qr < tl) return num_t::null_v;
    int mid = (tl + tr) / 2;
    num_t a = query(2 * i + 1, tl, mid, ql, qr),
          b = query(2 * i + 2, mid + 1, tr, ql, qr);
    return a.op(b);
  }
  void eval_lazy(int i, int l, int r) {
    tree[i] = tree[i].lazy_op(lazy[i], (r - l + 1));
    if (l != r) {
      lazy[i * 2 + 1] = lazy[i].val + lazy[i * 2 + 1].val;
      lazy[i * 2 + 2] = lazy[i].val + lazy[i * 2 + 2].val;
    }
    lazy[i] = num_t();
  }
};
struct min_t {
  long long val;
  int ind;
  static const long long null_v = 9223372036854775807LL;
  min_t() : val(0) {}
  min_t(long long v) : val(v) {}
  min_t(long long v, int i) : val(v), ind(i){};
  min_t op(min_t& other) {
    if (other.val == val) return (ind > other.ind) ? other : *this;
    return (val > other.val) ? other : *this;
  }
  min_t lazy_op(min_t v, int size) { return min_t(val + v.val, ind); }
};
long long n, m, k, q, Q, T, l, r, x, y, z;
long long a[1000005];
long long b[1000005];
long long c[1000005];
string second, t;
long long ans = 0;
pair<pair<int, int>, int> query[500005];
int loc[500005];
int res[500005];
segtree<min_t> st;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  cin >> n;
  for (int ele = 0; ele < n; ele++) cin >> a[ele];
  ;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> query[i].first.second >> query[i].first.first;
    --query[i].first.first;
    --query[i].first.second;
    query[i].second = i;
  }
  int mx = 500005;
  sort(query, query + q);
  for (long long i = 0; i < q; i++)
    swap(query[i].first.first, query[i].first.second);
  for (long long i = 0; i < mx; i++) c[i] = 1e7;
  st.init(n, c);
  for (long long i = 0; i < mx; i++) loc[i] = -1;
  for (long long i = 0; i < n; i++) {
    b[i] = loc[a[i]];
    loc[a[i]] = i;
  }
  for (long long i = 0; i < mx; i++) loc[i] = -1;
  int pt = 0;
  for (long long i = 0; i < n; i++) {
    if (loc[a[i]] != -1) {
      st.update(loc[a[i]], loc[a[i]], 1e7);
    }
    loc[a[i]] = i;
    st.update(i, i, b[i] - 1e7);
    while (query[pt].first.second == i) {
      min_t v = st.query(query[pt].first.first, query[pt].first.second);
      if (v.val >= query[pt].first.first)
        res[query[pt].second] = 0;
      else
        res[query[pt].second] = a[v.ind];
      ++pt;
    }
  }
  for (long long i = 0; i < q; i++) cout << res[i] << '\n';
}
