#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const long long int MAXN = 5e5 + 5;
const long long int N = 1e6 + 5;
long long int n, m;
long long int BLOCK = 555;
struct query {
  long long int l, r, i;
  inline bool operator<(const query &o) const {
    if (l / BLOCK != o.l / BLOCK) return l < o.l;
    return l / BLOCK & 1 ? r < o.r : r > o.r;
  }
} Q[500005];
long long int ar[500005], ans[500005];
long long int freq[1000001];
vector<long long int> v;
bool alreadyInV[N];
inline void updateV(long long int pos) {
  if (freq[ar[pos]] == 1 && !alreadyInV[ar[pos]]) {
    alreadyInV[ar[pos]] = true;
    v.push_back(ar[pos]);
  }
}
inline void add(long long int pos) {
  freq[ar[pos]]++;
  updateV(pos);
}
inline void remove(long long int pos) {
  freq[ar[pos]]--;
  updateV(pos);
}
void solve() {
  long long int q;
  cin >> n;
  BLOCK = sqrt(n);
  for (long long int i = 0; i < n; i++) cin >> ar[i];
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    cin >> Q[i].l >> Q[i].r;
    Q[i].i = i;
    Q[i].l--, Q[i].r--;
  }
  sort(Q, Q + q);
  long long int ML = 0, MR = -1;
  for (long long int i = 0; i < q; i++) {
    long long int L = Q[i].l;
    long long int R = Q[i].r;
    while (ML < L) {
      remove(ML), ML++;
    }
    while (ML > L) {
      ML--, add(ML);
    }
    while (MR < R) {
      MR++, add(MR);
    }
    while (MR > R) {
      remove(MR), MR--;
    }
    while (!v.empty() && freq[v.back()] != 1) {
      alreadyInV[v.back()] = 0;
      v.pop_back();
    }
    ans[Q[i].i] = v.empty() ? 0 : v.back();
  }
  for (long long int i = 0; i < q; i++) cout << ans[i] << "\n";
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  while (T--) solve();
  return 0;
}
