#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
struct query {
  int l, pos;
};
const int MAXN = 5e5, TREE_SZ = 2 * 1048576, INF = 2e9;
vector<query> queries[MAXN];
vector<int> nums, ans;
int tree[TREE_SZ];
int n;
void input() {
  cin >> n;
  nums.resize(n);
  for (int i = 0; i < n; i++) cin >> nums[i];
  int q;
  cin >> q;
  ans.resize(q);
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    queries[r - 1].push_back({l - 1, i});
  }
}
void upd(int v, int pos, int val, int lb, int rb) {
  if (lb == rb && lb == pos) {
    tree[v] = val;
    return;
  }
  int mid = (lb + rb) / 2;
  if (pos <= mid)
    upd(2 * v, pos, val, lb, mid);
  else
    upd(2 * v + 1, pos, val, mid + 1, rb);
  tree[v] = min(tree[2 * v], tree[2 * v + 1]);
}
void upd(int pos, int val) { upd(1, pos, val, 0, 2 * n - 1); }
int get_min(int v, int l, int r, int lb, int rb) {
  if (l > rb || r < lb) return INF;
  if (l == lb && r == rb) return tree[v];
  int mid = (lb + rb) / 2;
  return min(get_min(2 * v, l, min(mid, r), lb, mid),
             get_min(2 * v + 1, max(l, mid + 1), r, mid + 1, rb));
}
int get_min(int l, int r) { return get_min(1, l, r, 0, 2 * n - 1); }
int last_enter[MAXN + 1];
void gen() {
  memset(last_enter, 255, sizeof(last_enter));
  memset(tree, 255, sizeof(tree));
  for (int i = 0; i < n; i++) last_enter[nums[i]] = i;
  for (int r = 0; r < n; r++) {
    int num = nums[r];
    if (last_enter[num] != -1) upd(last_enter[num], INF);
    upd(r + n, last_enter[num]);
    last_enter[num] = r + n;
    for (query cur : queries[r]) {
      int pos = get_min(cur.l + n, r + n);
      if (pos < cur.l + n) {
        if (pos >= n) pos -= n;
        ans[cur.pos] = nums[pos];
      } else
        ans[cur.pos] = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  input();
  gen();
  for (int x : ans) cout << x << '\n';
}
