#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)(5e5 + 5);
const long long mod = (long long)(1e9 + 7);
int l[maxn], r[maxn], a[maxn];
int pos[maxn];
vector<pair<int, pair<int, int> > > tree[4 * maxn];
void print(int *x, int n) {
  for (int i = 0; i < n; i++) {
    cerr << *(x + i) << " ";
  }
}
vector<pair<int, pair<int, int> > > merge(
    vector<pair<int, pair<int, int> > > &l,
    vector<pair<int, pair<int, int> > > &r) {
  int ptr1 = 0, ptr2 = 0;
  vector<pair<int, pair<int, int> > > ret;
  while (ptr1 < l.size() || ptr2 < r.size()) {
    if (ptr1 == l.size()) {
      ret.push_back(r[ptr2]);
      ptr2++;
    } else if (ptr2 == r.size()) {
      ret.push_back(l[ptr1]);
      ptr1++;
    } else if (l[ptr1].first <= r[ptr2].first) {
      ret.push_back(l[ptr1]);
      ptr1++;
    } else {
      ret.push_back(r[ptr2]);
      ptr2++;
    }
  }
  int val1 = ret[0].second.first, val2 = ret[0].second.second;
  for (int i = 1; i < ret.size(); i++) {
    if (ret[i].second.second < val2) {
      ret[i].second.first = val1;
      ret[i].second.second = val2;
    } else {
      val2 = ret[i].second.second;
      val1 = ret[i].second.first;
    }
  }
  return ret;
}
void build(int node, int s, int e) {
  if (s > e) {
    return;
  }
  if (s == e) {
    vector<pair<int, pair<int, int> > > v;
    v.push_back({l[s], {a[s], r[s]}});
    tree[node] = v;
  } else {
    int mid = (s + e) >> 1;
    build(node << 1, s, mid);
    build(node << 1 | 1, mid + 1, e);
    tree[node] = merge(tree[node << 1], tree[node << 1 | 1]);
  }
}
pair<int, int> zz(pair<int, int> &a, pair<int, int> &b) {
  if (a.second > b.second) {
    return a;
  }
  return b;
}
pair<int, int> get(vector<pair<int, pair<int, int> > > &v, int x) {
  int low = 0, high = v.size() - 1;
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    if (v[mid].first < x) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  if (low < v.size() && v[low].first < x) {
    return {v[low].second.first, v[low].second.second};
  }
  return {0, -1};
}
pair<int, int> query(int node, int s, int e, int l, int r, int x) {
  if (s > e || l > e || r < s) {
    return {0, -1};
  } else if (l <= s && r >= e) {
    pair<int, int> now = get(tree[node], x);
    return now;
  } else {
    int mid = (s + e) >> 1;
    pair<int, int> q1 = query(node << 1, s, mid, l, r, l),
                   q2 = query(node << 1 | 1, mid + 1, e, l, r, l);
    return zz(q1, q2);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  fill(pos, pos + maxn, -1);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    l[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  fill(pos, pos + maxn, n);
  for (int i = n - 1; i >= 0; i--) {
    r[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  build(1, 0, n - 1);
  int q;
  scanf("%d", &q);
  while (q > 0) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    pair<int, int> now = query(1, 0, n - 1, l, r, l);
    if (now.second > r) {
      printf("%d\n", now.first);
    } else {
      printf("%d\n", 0);
    }
    q--;
  }
  return 0;
}
