#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e17;
struct node {
  node *l, *r;
  pair<int, int> val;
  node() {
    l = 0, r = 0;
    val = {INF, -1};
  }
  node(int pos, int vl) {
    l = r = 0;
    val = {vl, pos};
  }
  node(node* a, node* b) {
    l = a;
    r = b;
    val = min(a->val, b->val);
  }
};
void build(node* v, int tl, int tr) {
  if (tl == tr) {
    v->val = {INF, -1};
    return;
  }
  int tm = (tl + tr) / 2;
  if (v->l == 0) v->l = new node();
  if (v->r == 0) v->r = new node();
  build(v->l, tl, tm);
  build(v->r, tm + 1, tr);
  v = new node(v->l, v->r);
}
node* upd(node* v, int tl, int tr, int pos, int val) {
  if (tl == tr) {
    return new node(pos, val);
  }
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    return new node(upd(v->l, tl, tm, pos, val), v->r);
  else
    return new node(v->l, upd(v->r, tm + 1, tr, pos, val));
}
pair<int, int> g(node* v, int tl, int tr, int l, int r) {
  if (l > r) return {INF, -1};
  if (tl == l && tr == r) return v->val;
  int tm = (tl + tr) / 2;
  return min(g(v->l, tl, tm, l, min(r, tm)),
             g(v->r, tm + 1, tr, max(tm + 1, l), r));
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> ar(n);
  for (int i = 0; i < n; i++) cin >> ar[i];
  vector<node*> nodes(n);
  nodes[0] = new node();
  build(nodes[0], 0, n - 1);
  unordered_map<int, int> lst;
  for (int i = 0; i < n; i++) {
    node* cur = (i == 0 ? nodes[i] : nodes[i - 1]);
    if (!lst.count(ar[i])) {
      cur = upd(cur, 0, n - 1, i, -1);
    } else {
      cur = upd(cur, 0, n - 1, lst[ar[i]], INF);
      cur = upd(cur, 0, n - 1, i, lst[ar[i]]);
    }
    lst[ar[i]] = i;
    nodes[i] = cur;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    pair<int, int> res = g(nodes[r], 0, n - 1, l, r);
    if (res.first < l)
      cout << ar[res.second] << "\n";
    else
      cout << 0 << "\n";
  }
}
