#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5, inf = 1e6;
int mi[maxn * 4 + 5];
int a[maxn + 5], pre[maxn + 5], now[maxn + 5];
int ans[maxn + 5];
int n, m;
vector<pair<int, int> > q[maxn + 5];
void update(int k) {
  mi[k] = mi[k * 2];
  if (pre[mi[k * 2 + 1]] < pre[mi[k]]) mi[k] = mi[k * 2 + 1];
}
void build(int k, int l, int r) {
  if (l > r) return;
  if (l == r) {
    mi[k] = n + 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(k * 2, l, mid);
  build(k * 2 + 1, mid + 1, r);
  update(k);
}
void modify(int k, int l, int r, int p, int x) {
  if (l == r) {
    mi[k] = x;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    modify(k * 2, l, mid, p, x);
  else
    modify(k * 2 + 1, mid + 1, r, p, x);
  update(k);
}
int query(int k, int l, int r, int ql, int qr) {
  if (l > r || l > qr || r < ql) return n + 1;
  if (l >= ql && r <= qr) return mi[k];
  if (l == r) return n + 1;
  int mid = (l + r) >> 1;
  int ans = query(k * 2, l, mid, ql, qr);
  int id = query(k * 2 + 1, mid + 1, r, ql, qr);
  if (pre[id] < pre[ans]) ans = id;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    q[r].push_back(make_pair(l, i));
  }
  pre[1] = 0;
  now[a[1]] = 1;
  for (int i = 2; i <= n; ++i) {
    pre[i] = now[a[i]];
    now[a[i]] = i;
  }
  pre[n + 1] = inf;
  build(1, 1, n);
  for (int i = 1; i <= n; ++i) {
    modify(1, 1, n, i, i);
    if (pre[i]) {
      modify(1, 1, n, pre[i], n + 1);
    }
    for (auto x : q[i]) {
      int id = query(1, 1, n, x.first, i);
      if (pre[id] < x.first) ans[x.second] = a[id];
    }
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
