#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
struct info {
  int l, r, id;
  info() {}
  info(int l, int r, int id) : l(l), r(r), id(id) {}
};
int n, q, a[5 * 100005], cnt[5 * 100005];
int exist;
const int blockSZ = 710;
info Q[5 * 100005];
int blocks[blockSZ], Ans[5 * 100005];
inline bool comp(const info &a, const info &b) {
  if (a.l / blockSZ != b.l / blockSZ) return a.l < b.l;
  if ((a.l / blockSZ) & 1) return a.r < b.r;
  return a.r > b.r;
}
inline void Add(int idx) {
  cnt[a[idx]]++;
  if (cnt[a[idx]] == 1) {
    blocks[a[idx] / blockSZ]++;
    exist++;
  } else if (cnt[a[idx]] == 2) {
    blocks[a[idx] / blockSZ]--;
    exist--;
  }
}
inline void Remove(int idx) {
  cnt[a[idx]]--;
  if (cnt[a[idx]] == 1) {
    blocks[a[idx] / blockSZ]++;
    exist++;
  } else if (cnt[a[idx]] == 0) {
    blocks[a[idx] / blockSZ]--;
    exist--;
  }
}
int getans() {
  if (!exist) return 0;
  int t = 0;
  for (int i = 0; i < 710; i++) {
    if (blocks[i] > 0) {
      t = i;
      break;
    }
  }
  for (int i = t * blockSZ;; i++) {
    if (cnt[i] == 1) return i;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (int i = (0); i < (q); i++) {
    scanf("%d%d", &Q[i].l, &Q[i].r);
    Q[i].l--;
    Q[i].r--;
    Q[i].id = i;
  }
  sort(Q, Q + q, comp);
  int Left = 0, Right = -1;
  for (int i = (0); i < (q); i++) {
    while (Left < Q[i].l) {
      Remove(Left);
      Left++;
    }
    while (Left > Q[i].l) {
      Left--;
      Add(Left);
    }
    while (Right < Q[i].r) {
      Right++;
      Add(Right);
    }
    while (Right > Q[i].r) {
      Remove(Right);
      Right--;
    }
    Ans[Q[i].id] = getans();
  }
  for (int i = (0); i < (q); i++) printf("%d\n", Ans[i]);
  return 0;
}
