#include <bits/stdc++.h>
char _buf[1 << 16];
int _pos = 1;
int _cap = 1;
char _obuf[1 << 16];
int _opos = 0;
unsigned char *_abuf;
int _apos = 1 << 20;
inline char nextChar() {
  if (_cap == 0) return 0;
  if (_pos == _cap) {
    _cap = (int)fread(_buf, 1, 1 << 16, stdin);
    if (_cap == 0) return 0;
    _pos = 0;
  }
  return _buf[_pos++];
}
template <typename T>
inline void nextInt(T &res) {
  char c = nextChar();
  while (isspace(c)) c = nextChar();
  res = 0;
  while (isdigit(c)) {
    res = res * 10 + c - '0';
    c = nextChar();
  }
}
char tmp;
template <typename T>
inline void putInt(T x) {
  if (x < 0) {
    _obuf[_opos++] = '-';
    x = -x;
  }
  int cur = _opos;
  while (x >= 10) {
    _obuf[_opos++] = (char)(x % 10 + '0');
    x /= 10;
  }
  _obuf[_opos++] = (char)(x + '0');
  for (int i = cur, j = _opos - 1; i < j; ++i, --j) {
    tmp = _obuf[i];
    _obuf[i] = _obuf[j];
    _obuf[j] = tmp;
  }
  if (_opos > 64000) {
    fwrite(_obuf, 1, _opos, stdout);
    _opos = 0;
  }
}
inline void putChar(char x) {
  _obuf[_opos++] = x;
  if (_opos > 64000) {
    fwrite(_obuf, 1, _opos, stdout);
    _opos = 0;
  }
}
inline void flushInt() {
  if (_opos) fwrite(_obuf, 1, _opos, stdout);
  fflush(stdout);
}
using namespace std;
const int N = 500500;
struct node {
  int l, r, id, ans;
} que[N];
int a[N], c[N];
bool vis[N];
int n, m;
int b;
int ans[N];
inline bool cmp(const node &x, const node &y) {
  if (x.l / b < y.l / b) return 1;
  if (x.l / b > y.l / b) return 0;
  return ((x.l / b) & 1) ? x.r < y.r : x.r > y.r;
}
vector<int> answer;
inline int cmp2(const node &x, const node &y) { return x.id < y.id; }
inline void op(int x) {
  if (c[x] == 1 && !vis[x]) answer.push_back(x), vis[x] = 1;
}
inline void add(int x) {
  c[a[x]]++;
  op(a[x]);
}
inline void del(int x) {
  c[a[x]]--;
  op(a[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() {
  nextInt(n);
  for (int i = 1; i <= n; i++) {
    nextInt(a[i]);
  }
  nextInt(m);
  b = sqrt(n + m);
  for (int i = 1; i <= m; i++) {
    nextInt(que[i].l);
    nextInt(que[i].r);
    que[i].id = i;
  }
  sort(que + 1, que + m + 1, cmp);
  int l = 1, r = 0;
  c[0] = 1;
  answer.push_back(0);
  for (int i = 1; i <= m; i++) {
    while (l > que[i].l) add(--l);
    while (l < que[i].l) del(l++);
    while (r < que[i].r) add(++r);
    while (r > que[i].r) del(r--);
    while (c[answer.back()] != 1) {
      vis[answer.back()] = 0;
      answer.pop_back();
    }
    ans[que[i].id] = answer.back();
  }
  for (int i = 1; i <= m; i++) {
    putInt(ans[i]);
    putChar('\n');
  }
  flushInt();
  return 0;
}
