#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
int n, nl[1000010];
int m;
int cnt[1000010];
int nxt[1000010], iee[1000010];
struct nod {
  int l, r, id;
} q[1000010];
int tree[2000020];
int ans[1000010];
void push_up(int id) { tree[id] = max(tree[id << 1], tree[id << 1 | 1]); }
void update(int id, int l, int r, int t, int k) {
  if (l > r) return;
  if (l == t && r == t) {
    tree[id] = k;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= t)
    update(id << 1, l, mid, t, k);
  else
    update(id << 1 | 1, mid + 1, r, t, k);
  push_up(id);
}
int Query(int id, int l, int r, int t) {
  if (l == r) return l;
  int mid = l + r >> 1;
  if (tree[id << 1] > t && mid >= l)
    return Query(id << 1, l, mid, t);
  else if (mid <= r)
    return Query(id << 1 | 1, mid + 1, r, t);
}
int query(int id, int l, int r, int tl, int tr) {
  if (l >= tl && r <= tr) {
    if (tree[id] <= tr) return -1;
    return Query(id, l, r, tr);
  }
  int mid = l + r >> 1;
  int ans = -1;
  if (mid >= tl) ans = max(ans, query(id << 1, l, mid, tl, tr));
  if (mid + 1 <= tr) ans = max(ans, query(id << 1 | 1, mid + 1, r, tl, tr));
  return ans;
}
bool cmp(nod a, nod b) { return a.l < b.l; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) nl[i] = read();
  for (int i = 1; i <= 5e5; i++) iee[i] = n + 1;
  for (int i = n; i >= 1; i--) {
    nxt[i] = iee[nl[i]];
    iee[nl[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[nl[i]] == 0) {
      cnt[nl[i]] = 1;
      update(1, 1, n, i, nxt[i]);
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    q[i].l = read();
    q[i].r = read();
    q[i].id = i;
  }
  sort(q + 1, q + m + 1, cmp);
  int l = 1;
  for (int i = 1; i <= m; i++) {
    while (q[i].l != l) {
      if (nxt[l] <= n) update(1, 1, n, nxt[l], nxt[nxt[l]]);
      l++;
    }
    int id = query(1, 1, n, q[i].l, q[i].r);
    if (id == -1)
      ans[q[i].id] = 0;
    else
      ans[q[i].id] = nl[id];
  }
  for (int i = 1; i <= m; i++) {
    writeln(ans[i]);
  }
  return 0;
}
