#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, m, k, a[N], size, cnt[N], pos[N], s[N], top, ans[N];
struct query {
  int l, r, id, be;
} q[N];
bool cmp(const query &a, const query &b) {
  if (a.be ^ b.be) return a.l < b.l;
  return a.be & 1 ? a.r < b.r : a.r > b.r;
}
void del(int x) {
  cnt[a[x]]--;
  if (cnt[a[x]] == 1) {
    s[++top] = a[x];
    pos[a[x]] = top;
  }
  if (!cnt[a[x]]) {
    s[pos[a[x]]] = s[top];
    pos[s[top--]] = pos[a[x]];
  }
  return;
}
void add(int x) {
  cnt[a[x]]++;
  if (cnt[a[x]] == 1) {
    s[++top] = a[x];
    pos[a[x]] = top;
  }
  if (cnt[a[x]] == 2) {
    s[pos[a[x]]] = s[top];
    pos[s[top--]] = pos[a[x]];
  }
  return;
}
int main() {
  scanf("%d", &n);
  size = sqrt(n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1, ql, qr; i <= m; i++) {
    scanf("%d%d", &ql, &qr);
    q[i].l = ql;
    q[i].r = qr;
    q[i].id = i;
    q[i].be = ql / size;
  }
  sort(q + 1, q + 1 + m, cmp);
  int l = 1, r = 0;
  for (int i = 1; i <= m; i++) {
    while (l < q[i].l) del(l++);
    while (l > q[i].l) add(--l);
    while (r < q[i].r) add(++r);
    while (r > q[i].r) del(r--);
    ans[q[i].id] = s[top];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
