#include <bits/stdc++.h>
using namespace std;
const int N = 500001;
const int sqN = 708;
int ans[N];
int fre[N];
int v[N];
int block[sqN];
int answer = 0;
struct query {
  int l;
  int r;
  int idx;
} Q[N];
bool comp(query &q1, query &q2) {
  if (q1.l / sqN != q2.l / sqN) {
    return q1.l < q2.l;
  }
  if ((q1.l / sqN) & 1) {
    return q1.r < q2.r;
  }
  return q1.r > q2.r;
}
inline void add(int idx) {
  int val = v[idx];
  fre[val]++;
  if (fre[val] == 1) {
    answer++;
    block[val / sqN]++;
  }
  if (fre[val] == 2) {
    answer--;
    block[val / sqN]--;
  }
}
inline void rem(int idx) {
  int val = v[idx];
  fre[val]--;
  if (fre[val] == 1) {
    answer++;
    block[val / sqN]++;
  }
  if (fre[val] == 0) {
    answer--;
    block[val / sqN]--;
  }
}
inline int solve() {
  if (answer == 0) {
    return 0;
  }
  for (int i = 0; i < sqN; i++) {
    if (block[i] > 0) {
      for (int j = i * sqN; j < i * sqN + sqN; j++) {
        if (fre[j] == 1) {
          return j;
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int q, l, r;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    l--;
    r--;
    Q[i].l = l;
    Q[i].r = r;
    Q[i].idx = i;
  }
  sort(Q, Q + q, comp);
  l = 0, r = -1;
  for (int i = 0; i < q; i++) {
    int L = Q[i].l;
    int R = Q[i].r;
    while (l < L) {
      rem(l);
      l++;
    }
    while (l > L) {
      l--;
      add(l);
    }
    while (r < R) {
      r++;
      add(r);
    }
    while (r > R) {
      rem(r);
      r--;
    }
    ans[Q[i].idx] = solve();
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
