#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }
void M() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
int n, arr[500009], L[500009], R[500009], last[500009];
vector<vector<int> > v(500009);
map<pair<int, int>, int> ans;
pair<int, int> tree[4 * 500009];
int inf = 500000 + 10;
void update(int l, int r, int p, int pos, int val) {
  if (l == r) {
    tree[p] = make_pair(val, pos);
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid) {
    update(l, mid, p * 2, pos, val);
  } else {
    update(mid + 1, r, p * 2 + 1, pos, val);
  }
  if (tree[p * 2].first < tree[p * 2 + 1].first)
    tree[p] = tree[p * 2];
  else
    tree[p] = tree[p * 2 + 1];
}
pair<int, int> query(int l, int r, int p, int a, int b) {
  if (b < l || r < a) return make_pair(inf, 0);
  if (l >= a && r <= b) {
    return tree[p];
  }
  int mid = (l + r) / 2;
  return min(query(l, mid, p * 2, a, b), query(mid + 1, r, p * 2 + 1, a, b));
}
int main() {
  M();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int q;
  cin >> q;
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    l--;
    r--;
    v[r].push_back(l);
    L[i] = l;
    R[i] = r;
  }
  memset(last, -1, sizeof(last));
  for (int i = 0; i < 500009; i++) tree[i] = make_pair(inf, 0);
  for (int i = 0; i < n; i++) {
    if (last[arr[i]] == -1)
      update(0, n - 1, 1, i, -1);
    else {
      update(0, n - 1, 1, i, last[arr[i]]);
      update(0, n - 1, 1, last[arr[i]], inf);
    }
    last[arr[i]] = i;
    for (int j = 0; j < ((int)(v[i]).size()); j++) {
      int nw = v[i][j];
      pair<int, int> ret = query(0, n - 1, 1, nw, i);
      if (ret.first >= nw)
        ans[make_pair(nw, i)] = 0;
      else
        ans[make_pair(nw, i)] = arr[ret.second];
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[make_pair(L[i], R[i])] << endl;
  }
}
