#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7, INF = 0x7fffffff;
struct Mo {
  int l, r, id;
} Q[N];
int pos[N], flag[N], sav[N], ans[N], sz;
char inv[N];
vector<int> E;
int n, q, L, R;
inline bool cmp(const Mo &x, const Mo &y) {
  if (x.l / sz < y.l / sz) return 1;
  if (x.l / sz > y.l / sz) return 0;
  return ((x.l / sz) & 1) ? x.r < y.r : x.r > y.r;
}
inline void read(int &x) {
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
}
inline void write(int &x) {
  if (x == 0) {
    putchar(48);
    return;
  }
  int len = 0, dg[20];
  while (x > 0) {
    dg[++len] = x % 10;
    x /= 10;
  }
  for (int i = len; i >= 1; i--) putchar(dg[i] + 48);
}
inline void Add(int &x) {
  ++flag[sav[x]];
  if (flag[sav[x]] == 1 && inv[sav[x]] == 0)
    E.push_back(sav[x]), inv[sav[x]] = 1;
}
inline void Del(int &x) {
  --flag[sav[x]];
  if (flag[sav[x]] == 1 & inv[sav[x]] == 0)
    E.push_back(sav[x]), inv[sav[x]] = 1;
}
inline void slove() {
  L = 1, R = 0;
  sort(Q + 1, Q + 1 + q, cmp);
  for (register int i = 1; i <= q; i++) {
    while (L > Q[i].l) --L, Add(L);
    while (L < Q[i].l) Del(L), ++L;
    while (R < Q[i].r) ++R, Add(R);
    while (R > Q[i].r) Del(R), --R;
    while (E.size() && flag[E.back()] != 1) {
      inv[E.back()] = 0;
      E.pop_back();
    }
    if (E.size())
      ans[Q[i].id] = E.back();
    else
      ans[Q[i].id] = 0;
  }
}
int main() {
  register int i, j;
  read(n);
  sz = sqrt(n);
  for (i = 1; i <= n; ++i) {
    read(sav[i]);
    pos[i] = i / sz;
  }
  read(q);
  for (i = 1; i <= q; ++i) {
    read(Q[i].l), read(Q[i].r);
    Q[i].id = i;
  }
  slove();
  for (i = 1; i <= q; i++) write(ans[i]), putchar('\n');
}
