#include <bits/stdc++.h>
using namespace std;
const int Max = 500500;
int n, a[Max], q, cnt[Max], outp[Max], belong[Max];
char vis[Max];
vector<int> ans;
struct node {
  int l, r, id;
} que[Max];
int cmp(const node& a, const node& b) {
  if (belong[a.l] == belong[b.l]) {
    if (belong[a.l] & 1) {
      return belong[a.r] < belong[b.r];
    }
    return belong[a.r] > belong[b.r];
  }
  return belong[a.l] < belong[b.l];
}
inline void op(int x) {
  if (cnt[x] == 1 && !vis[x]) ans.push_back(x), vis[x] = 1;
}
inline void add(int x) {
  cnt[x]++;
  op(x);
}
inline void cut(int x) {
  cnt[x]--;
  op(x);
}
inline void Read(int& x) {
  char c = getchar();
  x = 0;
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
inline void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a > 9) Out(a / 10);
  putchar(a % 10 + '0');
}
int main() {
  int i, l = 1, r = 0;
  scanf("%d", &n);
  int ze = sqrt(n);
  for (i = 1; i <= n; i++) {
    Read(a[i]);
    belong[i] = i / ze;
  }
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    Read(que[i].l);
    Read(que[i].r);
    que[i].id = i;
  }
  sort(que + 1, que + 1 + q, cmp);
  cnt[0] = 1;
  ans.push_back(0);
  for (i = 1; i <= q; i++) {
    while (que[i].l < l) {
      add(a[--l]);
    }
    while (que[i].l > l) {
      cut(a[l++]);
    }
    while (que[i].r > r) {
      add(a[++r]);
    }
    while (que[i].r < r) {
      cut(a[r--]);
    }
    while (cnt[ans.back()] != 1) {
      vis[ans.back()] = 0;
      ans.pop_back();
    }
    outp[que[i].id] = ans.back();
  }
  for (i = 1; i <= q; i++) Out(outp[i]), putchar('\n');
  return 0;
}
