#include <bits/stdc++.h>
using namespace std;
const int BBB = 707;
const int N = 500000;
int n, m, num[500100], BLK[500100], lp[800], cnt[500100], tot[800], res[500100];
struct query {
  int l, r, id;
  friend bool operator<(const query &x, const query &y) {
    if (BLK[x.l] != BLK[y.l]) return BLK[x.l] < BLK[y.l];
    return BLK[x.l] & 1 ? x.r > y.r : x.r < y.r;
  }
} q[500100];
void Push(int x) {
  tot[BLK[num[x]]] -= (cnt[num[x]] == 1);
  cnt[num[x]]++;
  tot[BLK[num[x]]] += (cnt[num[x]] == 1);
}
void Pop(int x) {
  tot[BLK[num[x]]] -= (cnt[num[x]] == 1);
  cnt[num[x]]--;
  tot[BLK[num[x]]] += (cnt[num[x]] == 1);
}
int calc() {
  for (int i = 0; i <= BLK[N]; i++) {
    if (!tot[i]) continue;
    for (int j = lp[i]; j < lp[i + 1]; j++)
      if (cnt[j] == 1) return j;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= N; i++) BLK[i] = i / BBB;
  for (int i = 0; i <= BLK[N]; i++) lp[i] = i * BBB;
  lp[BLK[N] + 1] = N + 1;
  for (int i = 0; i < n; i++) scanf("%d", &num[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &q[i].l, &q[i].r), q[i].l--, q[i].r--, q[i].id = i;
  sort(q + 1, q + m + 1);
  Push(0);
  for (int i = 1, L = 0, R = 0; i <= m; i++) {
    while (L > q[i].l) Push(--L);
    while (R < q[i].r) Push(++R);
    while (L < q[i].l) Pop(L++);
    while (R > q[i].r) Pop(R--);
    res[q[i].id] = calc();
  }
  for (int i = 1; i <= m; i++) printf("%d\n", res[i]);
  return 0;
}
