#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x *= f;
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 5e5 + 10;
int n, m, l = 1, r, siz, top, a[maxn], cnt[maxn], pos[maxn], stk[maxn],
          belong[maxn];
int ans[maxn];
struct query {
  int l, r, id;
  friend inline bool operator<(query a, query b) {
    return (belong[a.l] ^ belong[b.l])
               ? a.l < b.l
               : ((belong[a.l] & 1) ? a.r < b.r : a.r > b.r);
  }
} q[maxn];
inline void add(int k) {
  pos[k] = ++top;
  stk[top] = k;
}
inline void del(int k) {
  stk[pos[k]] = stk[top];
  pos[stk[top]] = pos[k];
  pos[k] = stk[top--] = 0;
}
inline void ADD(int k) {
  if (cnt[a[k]] == 1)
    del(a[k]);
  else if (!cnt[a[k]])
    add(a[k]);
  ++cnt[a[k]];
}
inline void DEL(int k) {
  if (cnt[a[k]] == 1)
    del(a[k]);
  else if (cnt[a[k]] == 2)
    add(a[k]);
  --cnt[a[k]];
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  read(m);
  siz = sqrt(n);
  for (int i = 1; i <= n; ++i) belong[i] = (i - 1) / siz + 1;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    read(u);
    read(v);
    q[i].l = u;
    q[i].r = v;
    q[i].id = i;
  }
  sort(q + 1, q + m + 1);
  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] = stk[top];
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
