#include <bits/stdc++.h>
using namespace std;
int last[500005];
int a[500005], b[500005], ans[500005];
vector<pair<int, int> > v[500005];
pair<int, int> st[2000005];
pair<int, int> min(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first) return a;
  return b;
}
void update(int n, int s, int e, int idx, int v) {
  if (s == e)
    st[n] = pair<int, int>(v, s);
  else {
    int mid = (s + e) / 2;
    if (idx <= mid)
      update(n + n, s, mid, idx, v);
    else
      update(n + n + 1, mid + 1, e, idx, v);
    st[n] = min(st[n + n], st[n + n + 1]);
  }
}
pair<int, int> query(int n, int s, int e, int l, int r) {
  if (s > r || l > e) return pair<int, int>(2e9, 0);
  if (l <= s && e <= r) return st[n];
  int mid = (s + e) / 2;
  return min(query(n + n, s, mid, l, r), query(n + n + 1, mid + 1, e, l, r));
}
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = last[a[i]];
    last[a[i]] = i;
    update(1, 1, n, i, b[i]);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    v[r].push_back(pair<int, int>(l, i));
  }
  for (int i = 1; i <= n; i++) {
    update(1, 1, n, i, b[i]);
    if (b[i] > 0) update(1, 1, n, b[i], 1e9);
    for (int j = 0; j < v[i].size(); j++) {
      int l = v[i][j].first, idx = v[i][j].second, r = i;
      pair<int, int> q = query(1, 1, n, l, r);
      if (q.first >= l)
        ans[idx] = 0;
      else
        ans[idx] = a[q.second];
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
