#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
int n, m;
int bs;
int a[MAXN];
int cnt[MAXN];
struct Query {
  int l, r, id;
  bool operator<(const Query& b) const {
    int b1 = l / bs, b2 = b.l / bs;
    if (b1 != b2)
      return b1 < b2;
    else
      return (b1 & 1) ? r > b.r : r < b.r;
  }
} qr[MAXN];
int ans[MAXN];
int bsa, nba;
int bn1[MAXN];
inline void add(int i) {
  cnt[a[i]]++;
  if (cnt[a[i]] == 1) {
    bn1[a[i] / bsa]++;
  } else if (cnt[a[i]] == 2) {
    bn1[a[i] / bsa]--;
  }
}
inline void sub(int i) {
  cnt[a[i]]--;
  if (cnt[a[i]] == 1) {
    bn1[a[i] / bsa]++;
  } else if (cnt[a[i]] == 0) {
    bn1[a[i] / bsa]--;
  }
}
void solve() {
  int l = 1, r = 0;
  for (int i = 0; i < m; i++) {
    while (r < qr[i].r) add(++r);
    while (r > qr[i].r) sub(r--);
    while (l < qr[i].l) sub(l++);
    while (l > qr[i].l) add(--l);
    for (int j = 0; j <= nba; j++) {
      if (bn1[j] > 0) {
        for (int k = j * bsa; k < (j + 1) * bsa; k++) {
          if (cnt[k] == 1) {
            ans[qr[i].id] = k;
            goto ct;
          }
        }
      }
    }
    ans[qr[i].id] = 0;
  ct:;
  }
}
int main() {
  scanf("%d", &n);
  int tmax = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    tmax = max(tmax, a[i]);
  }
  bsa = sqrt(tmax);
  nba = tmax / bsa + 1;
  scanf("%d", &m);
  bs = sqrt(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &qr[i].l, &qr[i].r);
    qr[i].id = i;
  }
  sort(qr, qr + m);
  solve();
  for (int i = 0; i < m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
