#include <bits/stdc++.h>
using namespace std;
double const EPS = 1.0E-9;
int const MOD = (int)1e9 + 7;
inline int read(char* s) { return scanf("%s", s); }
inline int read(int& x) { return scanf("%d", &(x)); }
inline int read(long long& x) { return scanf("%lld", &x); }
inline int read(double& x) { return scanf("%lf", &x); }
inline int writeln(int x) { return printf("%d\n", x); }
inline int writeln(long long x) { return printf("%lld\n", x); }
inline int writeln(double x) { return printf("%.12f\n", x); }
template <typename... T>
int read(T&... args) {
  using swallow = int[];
  swallow w = {0, (read(args))...};
  return sizeof(w) / sizeof(w[0]) - 1;
}
template <typename T>
int read(std::vector<T>& v) {
  for (T& t : v) read(t);
  return (int)v.size();
}
inline long long gcd(long long x, long long y) {
  return y == 0 ? x : gcd(y, x % y);
}
inline long long lcm(long long x, long long y) {
  return x == 0 && y == 0 ? 0 : x / gcd(x, y) * y;
}
inline long long powmod(long long x, long long n, long long m = MOD) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * x) % m;
    x = (x * x) % m;
    n /= 2;
  }
  return r;
}
static int leap(int y) { return y % 4 == 0 && y % 100 != 0 || y % 400 == 0; }
static int const month[2][12] = {
    {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
static const int maxn = 1 << 19;
static const int maxm = 1 << 22;
static const int P = 998244353;
int n, m;
int a[maxn], pos[maxn], ans[maxn];
struct query {
  int l, r, id;
} q[maxn];
struct segment_tree {
  int mn[maxn * 2], val[maxn * 2];
  void init() {
    memset(val, 0, sizeof(val));
    memset(mn, 0x33, sizeof(mn));
  }
  void update(int pos, int l) {
    int p = pos + maxn;
    mn[p] = l;
    val[p] = a[pos];
    while (p > 1) {
      p >>= 1;
      if (mn[p << 1] < mn[p << 1 | 1]) {
        mn[p] = mn[p << 1];
        val[p] = val[p << 1];
      } else {
        mn[p] = mn[p << 1 | 1];
        val[p] = val[p << 1 | 1];
      }
    }
  }
  int query(int l, int r) {
    int l_save = l;
    int ans_mn = 0x33333333;
    int ans_val = 0;
    for (l += maxn, r += maxn; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        if (ans_mn > mn[l]) {
          ans_mn = mn[l];
          ans_val = val[l];
        }
        ++l;
      }
      if (r & 1) {
        --r;
        if (ans_mn > mn[r]) {
          ans_mn = mn[r];
          ans_val = val[r];
        }
      }
    }
    return ans_mn < l_save ? ans_val : 0;
  }
} tree;
int solve() {
  tree.init();
  read(n);
  for (int i = 0; i < n; ++i) read(a[i]);
  read(m);
  for (int i = 0; i < m; ++i) {
    read(q[i].l, q[i].r);
    --q[i].l;
    --q[i].r;
    q[i].id = i;
  }
  sort(q, q + m, [](query a, query b) { return a.r < b.r; });
  for (int i = 0; i < maxn; ++i) pos[i] = -1;
  int lst = -1;
  for (int i = 0; i < m; ++i) {
    int r = q[i].r;
    for (int j = lst + 1; j <= r; ++j) {
      if (pos[a[j]] != -1) {
        tree.update(pos[a[j]], n + 1);
      }
      tree.update(j, pos[a[j]]);
      pos[a[j]] = j;
    }
    ans[q[i].id] = tree.query(q[i].l, q[i].r + 1);
    lst = r;
  }
  for (int i = 0; i < m; ++i) {
    writeln(ans[i]);
  }
  return 0;
}
int main(int argc, char* argv[]) {
  solve();
  return 0;
}
