#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const double eps = 0.00001;
const int SZ = 5e5 + 1;
int b[SZ];
pair<int, int> a[SZ];
tuple<int, int, int> c[SZ];
struct node {
  vector<pair<int, int> > mx;
  vector<tuple<int, int, int> > v;
  int l, r;
  node *left, *right;
};
node *build(int l, int r) {
  node *res = new node;
  res->l = l;
  res->r = r;
  if (l == r) {
    res->left = res->right = nullptr;
    res->v.push_back(c[l]);
    res->mx.push_back(make_pair(get<1>(c[l]), b[l]));
  } else {
    res->mx = vector<pair<int, int> >(r - l + 1, make_pair(0, 0));
    int mid = (l + r) / 2;
    res->left = build(l, mid);
    res->right = build(mid + 1, r);
    merge(res->left->v.begin(), res->left->v.end(), res->right->v.begin(),
          res->right->v.end(), back_inserter(res->v));
    pair<int, int> mxr = make_pair(0, 0);
    for (int i = 0; i < r - l + 1; i++) {
      mxr = max(mxr, make_pair(get<1>(res->v[i]), get<2>(res->v[i])));
      if (i) res->mx[i] = res->mx[i - 1];
      res->mx[i] = max(res->mx[i], mxr);
    }
  }
  return res;
}
int f = 0;
int query(node *root, int l, int r) {
  if (f || root->l > r || root->r < l) return 0;
  if (root->l >= l && root->r <= r) {
    int i = lower_bound(root->v.begin(), root->v.end(), make_tuple(l, 0, 0)) -
            root->v.begin();
    if (!i || root->mx[i - 1].first <= r) return 0;
    f = 1;
    return root->mx[i - 1].second;
  }
  return max(query(root->left, l, r), query(root->right, l, r));
}
int main() {
  int n, q, l, r;
  scanf("%i", &n);
  for (int i = 0; i < n; i++) scanf("%i", &b[i]);
  map<int, int> last;
  for (int i = 0; i < n; i++) {
    if (last.find(b[i]) == last.end())
      a[i].first = -INF;
    else
      a[i].first = last[b[i]];
    last[b[i]] = i;
  }
  last.clear();
  for (int i = n - 1; i >= 0; i--) {
    if (last.find(b[i]) == last.end())
      a[i].second = INF;
    else
      a[i].second = last[b[i]];
    last[b[i]] = i;
  }
  for (int i = 0; i < n; i++) c[i] = make_tuple(a[i].first, a[i].second, b[i]);
  node *root = build(0, n - 1);
  scanf("%i", &q);
  while (q--) {
    f = 0;
    scanf("%i%i", &l, &r);
    printf("%i\n", query(root, --l, --r));
  }
  return 0;
}
