#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, z, m, q, h, r, timer, mx, l, cnt, u, v, tot, y, INF, ans;
int a[1200005], res[1205000];
pair<int, int> b[1205000], t[1205000];
pair<pair<int, int>, int> queries[500500];
map<int, int> lst;
void modify(int p, pair<int, int> value) {
  for (t[p += n] = value; p > 1; p >>= 1) t[p >> 1] = min(t[p], t[p ^ 1]);
}
pair<int, int> query(int l, int r) {
  pair<int, int> res = make_pair(998244353, 998244353);
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = min(res, t[l++]);
    if (r & 1) res = min(res, t[--r]);
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) modify(i, make_pair(998244353, 998244353));
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    r--;
    queries[i] = make_pair(make_pair(r, l), i);
  }
  sort(queries, queries + q);
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (b[a[i]].first == 0 && b[a[i]].second == 0) {
      b[a[i]].second = i;
      modify(i, make_pair(-1, a[i]));
      b[a[i]].first = -1;
    } else {
      modify(b[a[i]].second, make_pair(998244353, 998244353));
      b[a[i]].first = b[a[i]].second;
      b[a[i]].second = i;
      modify(i, make_pair(b[a[i]].first, a[i]));
    }
    while (j < q && queries[j].first.first == i) {
      int l = queries[j].first.second;
      int num = queries[j].second;
      pair<int, int> mag = query(l, i + 1);
      if (mag < make_pair(l - 1, 998244353)) res[num] = mag.second;
      j++;
    }
  }
  for (int i = 0; i < q; i++) {
    printf("%d\n", res[i]);
  }
  return 0;
}
