#include <bits/stdc++.h>
using namespace std;
struct Query {
  int id, l, r, solution;
  Query() {}
  void olvas(int i) {
    id = i;
    cin >> l >> r;
    l--;
    r--;
  }
  const bool operator<(Query masik) const { return r < masik.r; }
};
const int maxn = 500005;
vector<Query> task;
int n, q;
int a[maxn], f[maxn];
int fa[maxn * 8];
map<int, int> ker;
void modosit(int hol, int tol, int ig, int poz, int val) {
  if (tol == ig) {
    fa[hol] = val;
    return;
  }
  int mid = (tol + ig) / 2;
  if (poz <= mid)
    modosit(hol * 2, tol, mid, poz, val);
  else
    modosit(hol * 2 + 1, mid + 1, ig, poz, val);
  fa[hol] = min(fa[hol * 2], fa[hol * 2 + 1]);
  return;
}
int leker(int hol, int tol, int ig, int from, int to) {
  if (from <= tol && ig <= to) {
    return fa[hol];
  }
  if (ig < from || to < tol) {
    return 1000000000;
    ;
  }
  int mid = (tol + ig) / 2;
  return min(leker(hol * 2, tol, mid, from, to),
             leker(hol * 2 + 1, mid + 1, ig, from, to));
}
bool kisebb(Query u, Query v) { return u.id < v.id; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  task.resize(q);
  for (int i = 0; i < q; i++) {
    task[i].olvas(i);
  }
  for (int i = 0; i < n; i++) {
    if (ker.count(a[i]) == 0) {
      f[i] = -a[i];
    } else {
      f[i] = ker[a[i]];
    }
    ker[a[i]] = i;
  }
  sort(task.begin(), task.end());
  int kesz = -1;
  for (int i = 0; i < q; i++) {
    while (kesz < task[i].r) {
      kesz++;
      if (f[kesz] >= 0) {
        modosit(1, 0, n - 1, f[kesz], f[kesz]);
      }
      modosit(1, 0, n - 1, kesz, f[kesz]);
    }
    int ans = leker(1, 0, n - 1, task[i].l, task[i].r);
    if (ans < 0)
      ans = -ans;
    else if (ans < task[i].l)
      ans = a[ans];
    else
      ans = 0;
    task[i].solution = ans;
  }
  sort(task.begin(), task.end(), kisebb);
  for (int i = 0; i < q; i++) {
    cout << task[i].solution << '\n';
  }
  return 0;
}
