#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<pair<int, int>> v[710];
pair<int, int> qs[500000];
map<pair<int, int>, int> anss;
queue<int> qu;
bool in[500001];
int l = 0, r = -1;
int x[500000];
int num[500001];
void add(int p) {
  num[x[p]]++;
  if (num[x[p]] == 1 and !in[x[p]]) {
    qu.push(x[p]);
    in[x[p]] = 1;
  }
}
void del(int p) {
  num[x[p]]--;
  if (num[x[p]] == 1 and !in[x[p]]) {
    qu.push(x[p]);
    in[x[p]] = 1;
  }
}
void solve(int p) {
  if (v[p].size() == 0) return;
  if (p % 2 == 0)
    sort(v[p].begin(), v[p].end());
  else
    sort(v[p].begin(), v[p].end(), greater<pair<int, int>>());
  for (int i = 0; i < v[p].size(); i++) {
    while (r < v[p][i].first) add(r + 1), r++;
    while (r > v[p][i].first) del(r), r--;
    while (l < v[p][i].second) del(l), l++;
    while (l > v[p][i].second) add(l - 1), l--;
    while (qu.size() and num[qu.front()] != 1) {
      in[qu.front()] = 0;
      qu.pop();
    }
    if (qu.size())
      anss[v[p][i]] = qu.front();
    else
      anss[v[p][i]] = 0;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    a--;
    b--;
    qs[i] = {b, a};
    v[(int)a / 710].push_back({b, a});
  }
  for (int i = 1; i <= 500000; i++) num[i] = 0, in[i] = 0;
  for (int i = 0; i < 710; i++) solve(i);
  for (int i = 0; i < q; i++) cout << anss[qs[i]] << "\n";
}
