#include <bits/stdc++.h>
using namespace std;
int n, m, b_si, a[500009], chk[500009], tot = 0, lbl[500009], lbr[500009];
struct data {
  int l, r, id, re, bl;
} sa[500009];
inline bool cmp(const data u1, const data u2) {
  return (u1.bl != u2.bl) ? (u1.l < u2.l)
                          : ((u1.bl & 1) ? (u1.r < u2.r) : (u1.r > u2.r));
}
static char buf[100000], *p1 = buf, *p2 = buf;
inline char fr() {
  return (p1 == p2 &&
          (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2))
             ? EOF
             : *p1++;
}
inline int qg() {
  int a = 0;
  char c = fr();
  while (!isdigit(c)) {
    c = fr();
  }
  while (isdigit(c)) {
    a = a * 10 + c - '0';
    c = fr();
  }
  return a;
}
inline void pr(int a, char c = '\n') {
  if (a || c == '\n') {
    pr(a / 10, a % 10 + '0');
  }
  putchar(c);
}
inline void run(int at, int v) {
  if (1 == (chk[a[at]])) {
    lbr[lbl[a[at]]] = lbr[a[at]];
    lbl[lbr[a[at]]] = lbl[a[at]];
  }
  if (1 == (chk[a[at]] += v)) {
    lbl[a[at]] = 0;
    lbr[a[at]] = lbr[0];
    lbl[lbr[0]] = a[at];
    lbr[0] = a[at];
  }
}
int main() {
  int l = 1, r = 0;
  n = qg();
  for (int i = (1), ilim = (n); i <= ilim; i++) a[i] = qg();
  m = qg();
  b_si = sqrt(n);
  for (int i = (1), ilim = (m); i <= ilim; i++)
    sa[i].l = qg(), sa[i].r = qg(), sa[i].id = i,
    sa[i].bl = (sa[i].l - 1) / b_si;
  sort(sa + 1, sa + 1 + m, cmp);
  lbr[0] = 500005;
  for (int i = (1), ilim = (m); i <= ilim; i++) {
    while (r < sa[i].r) run(++r, 1);
    while (r > sa[i].r) run(r--, -1);
    while (l < sa[i].l) run(l++, -1);
    while (l > sa[i].l) run(--l, 1);
    sa[i].re = (lbr[0] == 500005) ? 0 : lbr[0];
  }
  sort(sa + 1, sa + 1 + m,
       [](const data u1, const data u2) { return u1.id < u2.id; });
  for (int i = (1), ilim = (m); i <= ilim; i++) {
    pr(sa[i].re);
  }
  return 0;
}
