#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
  return x * f;
}
inline char char_read() {
  char ch = getchar();
  while (!isalpha(ch)) ch = getchar();
  return ch;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
inline void writes(long long x) { write(x), putchar(' '); }
inline void Writes(long long x) { write(x), putchar('\n'); }
int n, m, A[501010];
vector<int> ask[501010], id[501010];
int ap[501010], nxt[501010];
int vis[501010];
int st[501010], top, val[501010];
int mmax[501010 << 2], tag[501010 << 2];
int ans[501010];
inline void Pushup(int x) { mmax[x] = max(mmax[(x << 1)], mmax[(x << 1 | 1)]); }
inline void Pushdown(int x) {
  tag[(x << 1)] = max(tag[(x << 1)], tag[x]),
            tag[(x << 1 | 1)] = max(tag[(x << 1 | 1)], tag[x]);
  mmax[(x << 1)] = max(mmax[(x << 1)], tag[x]),
             mmax[(x << 1 | 1)] = max(mmax[(x << 1 | 1)], tag[x]);
}
void Build(int x, int l, int r) {
  if (l == r) {
    mmax[x] = val[((l + r) >> 1)];
    return;
  }
  Build((x << 1), l, ((l + r) >> 1)),
      Build((x << 1 | 1), ((l + r) >> 1) + 1, r);
  Pushup(x);
}
void Add(int x, int l, int r, int ql, int qr, int k) {
  if (ql <= l and r <= qr) {
    mmax[x] = max(mmax[x], k), tag[x] = max(tag[x], k);
    return;
  }
  if (ql <= ((l + r) >> 1)) Add((x << 1), l, ((l + r) >> 1), ql, qr, k);
  if (qr > ((l + r) >> 1)) Add((x << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, k);
  Pushup(x);
}
int Query(int x, int l, int r, int loc) {
  if (l == r) return mmax[x];
  Pushdown(x);
  if (loc <= ((l + r) >> 1))
    return Query((x << 1), l, ((l + r) >> 1), loc);
  else
    return Query((x << 1 | 1), ((l + r) >> 1) + 1, r, loc);
}
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) A[i] = read(), ap[A[i]] = n + 1;
  nxt[n + 1] = n + 1;
  for (register int i = n; i >= 1; --i) nxt[i] = ap[A[i]], ap[A[i]] = i;
  for (register int i = 1; i <= n; ++i) {
    vis[A[i]]++, st[++top] = i;
    while (top and vis[A[st[top]]] > 1) --top;
    val[i] = st[top];
  }
  Build(1, 1, n);
  m = read();
  for (register int i = 1; i <= m; ++i) {
    int l = read(), r = read();
    ask[l].push_back(r), id[l].push_back(i);
  }
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 0; j < ask[i].size(); ++j) {
      int loc = Query(1, 1, n, ask[i][j]);
      if (loc >= i)
        ans[id[i][j]] = A[loc];
      else
        ans[id[i][j]] = 0;
    }
    int a = i, b = nxt[i], c = nxt[nxt[i]];
    if (c > b) {
      Add(1, 1, n, b, c - 1, b);
    }
  }
  for (register int i = 1; i <= m; ++i) Writes(ans[i]);
  return 0;
}
