#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > ar[500010], tree[22][500010];
pair<int, int> moa[22][500010];
int n, pre[500010], nex[500010], val[500010];
void mergeIt(int b, int e, int l, int r, int lev) {
  int x = b, y = r;
  for (int p = b; b <= e || l <= r; p++) {
    if (b > e || (tree[lev + 1][l].first <= tree[lev + 1][b].first && l <= r)) {
      tree[lev][p] = tree[lev + 1][l];
      l++;
    } else {
      tree[lev][p] = tree[lev + 1][b];
      b++;
    }
  }
  int dude = -1, daam;
  for (int i = x; i <= y; i++) {
    if (dude < tree[lev][i].second.first) {
      dude = tree[lev][i].second.first;
      daam = tree[lev][i].second.second;
    }
    moa[lev][i] = {dude, daam};
  }
}
void divide(int b, int e, int lev) {
  if (b < e) {
    int mid = (b + e) >> 1;
    divide(b, mid, lev + 1);
    divide(mid + 1, e, lev + 1);
    mergeIt(b, mid, mid + 1, e, lev);
  } else {
    tree[lev][b] = ar[b];
    moa[lev][b] = {tree[lev][b].second.first, tree[lev][b].second.second};
  }
  return;
}
int query(int lev, int b, int e, int st, int en, int mina, int raju) {
  if (st > e || en < b) return -1;
  if (st <= b && en >= e) {
    int low = b, high = e, mid, v = -1, ret;
    while (low <= high) {
      mid = (low + high) >> 1;
      if (tree[lev][mid].first < mina)
        low = mid + 1, v = max(v, mid);
      else
        high = mid - 1;
    }
    if (v != -1 && moa[lev][v].first > raju)
      v = moa[lev][v].second;
    else
      v = -1;
    return v;
  }
  int mid = (b + e) >> 1;
  int ret = query(lev + 1, b, mid, st, en, mina, raju);
  if (ret != -1) return ret;
  return query(lev + 1, mid + 1, e, st, en, mina, raju);
}
int main() {
  ios::sync_with_stdio(false);
  int q, l, r;
  scanf("%d", &n);
  for (int i = 0; i <= n - 1; i++) scanf("%d", &val[i]);
  for (int i = 0; i <= 500010 - 1; i++) pre[i] = -1, nex[i] = n;
  for (int i = 0; i <= n - 1; i++) {
    ar[i].first = pre[val[i]];
    pre[val[i]] = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    ar[i].second = {nex[val[i]], val[i]};
    nex[val[i]] = i;
  }
  divide(0, n - 1, 0);
  scanf("%d", &q);
  for (int i = 0; i <= q - 1; i++) {
    scanf("%d %d", &l, &r);
    l--;
    r--;
    int prin = query(0, 0, n - 1, l, r, l, r);
    if (prin == -1) prin = 0;
    printf("%d\n", prin);
  }
  return 0;
}
