#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, b, id;
} q[500000 + 5];
int n, m, a[500000 + 5], bs, l = 1, r, ans[500000 + 5], st[500000 + 5], top,
                             cnt[500000 + 5], pos[500000 + 5];
inline int cmp(node x, node y) {
  return (x.b == y.b) ? (x.b % 2 == 1 ? x.r < y.r : x.r > y.r) : x.l < y.l;
}
inline void add(int x) {
  cnt[a[x]]++;
  if (cnt[a[x]] == 1) {
    st[++top] = a[x];
    pos[a[x]] = top;
  } else if (cnt[a[x]] == 2) {
    st[pos[a[x]]] = st[top];
    pos[st[top]] = pos[a[x]];
    st[top--] = pos[a[x]] = 0;
  }
}
inline void del(int x) {
  cnt[a[x]]--;
  if (cnt[a[x]] == 1) {
    st[++top] = a[x];
    pos[a[x]] = top;
  } else if (cnt[a[x]] == 0) {
    st[pos[a[x]]] = st[top];
    pos[st[top]] = pos[a[x]];
    st[top--] = pos[a[x]] = 0;
  }
}
inline int read() {
  int X(0), w(0);
  char ch(0);
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
int main() {
  n = read();
  bs = sqrt(n);
  for (register int i = 1; i <= n; i++) a[i] = read();
  scanf("%d", &m);
  for (register int i = 1; i <= m; i++) {
    q[i].l = read();
    q[i].r = read();
    q[i].id = i;
    q[i].b = q[i].l / bs;
  }
  sort(q + 1, q + m + 1, cmp);
  for (register int i = 1; i <= m; i++) {
    while (l > q[i].l) add(--l);
    while (r < q[i].r) add(++r);
    while (l < q[i].l) del(l++);
    while (r > q[i].r) del(r--);
    ans[q[i].id] = st[top];
  }
  for (register int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
