#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }
void M() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 500001;
const int sq = 708;
int res = 0, blockres[sq], cnt[N];
int arr[N], ans[N];
struct query {
  int l, r, id;
} Q[N];
bool cmp(query &a, query &b) {
  if (a.l / sq != b.l / sq) return (a.l < b.l);
  if ((a.l / sq) & 1) return (a.r < b.r);
  return (a.r > b.r);
}
void Remove(int id) {
  int val = arr[id];
  cnt[val]--;
  if (cnt[val] == 1) {
    res++;
    blockres[val / sq]++;
  }
  if (cnt[val] == 0) {
    res--;
    blockres[val / sq]--;
  }
}
void Add(int id) {
  int val = arr[id];
  cnt[val]++;
  if (cnt[val] == 1) {
    res++;
    blockres[val / sq]++;
  }
  if (cnt[val] == 2) {
    res--;
    blockres[val / sq]--;
  }
}
int Get() {
  if (res == 0) return 0;
  for (int i = 0; i < sq; i++) {
    if (blockres[i] == 0) continue;
    for (int j = i * sq; j < i * sq + sq; j++) {
      if (cnt[j] == 1) return j;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int q;
  scanf("%d", &q);
  int l, r;
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    l--;
    r--;
    Q[i].l = l;
    Q[i].r = r;
    Q[i].id = i;
  }
  sort(Q, Q + q, cmp);
  int curL = 0, curR = -1;
  for (int i = 0; i < q; i++) {
    int l = Q[i].l;
    int r = Q[i].r;
    while (curL < l) {
      Remove(curL);
      curL++;
    }
    while (curL > l) {
      curL--;
      Add(curL);
    }
    while (curR < r) {
      curR++;
      Add(curR);
    }
    while (curR > r) {
      Remove(curR);
      curR--;
    }
    ans[Q[i].id] = Get();
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
}
