#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int INF = 0x3f3f3f3f;
struct qry {
  int l, r, idx, ans;
};
int n, q, a[N], f[N], last[N];
vector<qry> qs;
pair<int, int> first[4 * N];
void update(int idx, int val, int p = 1, int l = 1, int r = n) {
  int mid = (l + r) / 2;
  if (l == r) {
    first[p] = {val, a[l]};
    return;
  }
  if (idx <= mid)
    update(idx, val, 2 * p, l, mid);
  else
    update(idx, val, 2 * p + 1, mid + 1, r);
  first[p] = min(first[2 * p], first[2 * p + 1]);
}
pair<int, int> query(int i, int j, int p = 1, int l = 1, int r = n) {
  if (j < l or i > r) return {INF, INF};
  if (i <= l and r <= j) return first[p];
  return min(query(i, j, 2 * p, l, (l + r) / 2),
             query(i, j, 2 * p + 1, (l + r) / 2 + 1, r));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> q;
  qs.resize(q);
  for (int i = 0; i < q; i++)
    cin >> qs[i].l >> qs[i].r, qs[i].idx = i, qs[i].ans = 0;
  sort(qs.begin(), qs.end(),
       [](qry a, qry b) { return a.r == b.r ? a.l < b.l : a.r < b.r; });
  for (int i = 0; i < 4 * N; i++) first[i] = {INF, INF};
  int ptr = 0;
  for (auto &x : qs) {
    while (ptr < x.r) {
      ptr++;
      f[a[ptr]] = last[a[ptr]];
      if (last[a[ptr]]) update(last[a[ptr]], INF);
      last[a[ptr]] = ptr;
      update(ptr, f[a[ptr]]);
    }
    pair<int, int> ans = query(x.l, x.r);
    if (ans.first < x.l) x.ans = ans.second;
  }
  sort(qs.begin(), qs.end(), [](qry a, qry b) { return a.idx < b.idx; });
  for (auto x : qs) cout << x.ans << "\n";
}
