#include <bits/stdc++.h>
using namespace std;
template <typename T>
class seg_extremum {
 public:
  vector<T> arr;
  int size, n;
  T inf;
  const bool is_max;
  seg_extremum(int m, T value, bool is_max) : is_max(is_max) {
    n = 1;
    while (n < m) n *= 2;
    size = n * 2;
    arr.resize(size);
    fill(arr.begin(), arr.end(), value);
    inf = value;
  }
  void update(int i, T v) {
    i += n;
    arr[i] = v;
    if (is_max)
      inf = min(inf, v);
    else
      inf = max(inf, v);
    while (i > 1) {
      i /= 2;
      if (is_max)
        arr[i] = max(arr[2 * i + 1], arr[2 * i]);
      else
        arr[i] = min(arr[2 * i + 1], arr[2 * i]);
    }
  }
  T range_extremum(int left, int right) {
    T res = inf;
    left += n, right += n;
    for (; left <= right; left = (left + 1) / 2, right = (right - 1) / 2) {
      if (left & 1) {
        if (is_max)
          res = max(res, arr[left]);
        else
          res = min(res, arr[left]);
      }
      if ((right & 1) == 0) {
        if (is_max)
          res = max(res, arr[right]);
        else
          res = min(res, arr[right]);
      }
    }
    return res;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  seg_extremum<pair<int, int>> seg(n, make_pair(n + 1, 0), false);
  vector<int> ta(505050, -1), prev(n);
  for (int i = 0; i < n; i++) {
    prev[i] = ta[a[i]];
    ta[a[i]] = i;
  }
  vector<vector<pair<int, int>>> query(n);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    r--, l--;
    query[r].push_back(make_pair(l, i));
  }
  vector<int> res(n);
  for (int i = 0; i < n; i++) {
    if (prev[i] != -1) {
      seg.update(prev[i], make_pair(1 << 29, -1));
    }
    seg.update(i, make_pair(prev[i] + 1, i));
    for (auto p0 : query[i]) {
      int l = p0.first;
      auto p = seg.range_extremum(l, i);
      if (p.first > l)
        res[p0.second] = 0;
      else
        res[p0.second] = a[p.second];
    }
  }
  for (int i = 0; i < m; i++) cout << res[i] << "\n";
  return 0;
}
