#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int base = 19260817;
const int INF = 1e9;
const int maxn = 2e5 + 10;
const double eps = 1e-8;
int add(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return 1LL * x * y % mod; }
int a[500010], pre[500010], minv[500010 << 2];
int L[500010], R[500010], ans[500010];
vector<int> que[500010];
void build(int o, int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
}
void update(int o, int l, int r, int pos, int v) {
  if (l == r) {
    minv[o] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(o << 1, l, mid, pos, v);
  else
    update(o << 1 | 1, mid + 1, r, pos, v);
  minv[o] = min(minv[o << 1], minv[o << 1 | 1]);
}
int query(int o, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return minv[o];
  int mid = (l + r) >> 1, res = INF;
  if (ll <= mid) res = min(res, query(o << 1, l, mid, ll, rr));
  if (rr > mid) res = min(res, query(o << 1 | 1, mid + 1, r, ll, rr));
  return res;
}
int find(int o, int l, int r, int ll, int rr, int v) {
  if (minv[o] > v) return INF;
  if (l == r) return l;
  int mid = (l + r) >> 1, res = INF;
  if (ll <= mid) res = find(o << 1, l, mid, ll, rr, v);
  if (res != INF) return res;
  if (rr > mid) res = find(o << 1 | 1, mid + 1, r, ll, rr, v);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> L[i] >> R[i];
    que[R[i]].push_back(i);
  }
  memset(pre, -1, sizeof(pre));
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    if (pre[a[i]] != -1) update(1, 1, n, pre[a[i]], INF);
    update(1, 1, n, i, pre[a[i]]);
    pre[a[i]] = i;
    for (int id : que[i]) {
      int l = L[id], r = R[id];
      int v = query(1, 1, n, l, r);
      if (v >= l)
        ans[id] = 0;
      else {
        int p = find(1, 1, n, l, r, v);
        ans[id] = a[p];
      }
    }
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << endl;
  return 0;
}
