#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500500;
struct node {
  int l, r, ID, num;
} q[Maxn];
int sum, ans[Maxn], kind[Maxn], be[Maxn];
int aaaas[Maxn], vis[Maxn];
int b;
inline bool cmp(const node &x, const node &y) {
  if (x.l / b < y.l / b) return 1;
  if (x.l / b > y.l / b) return 0;
  return ((x.l / b) & 1) ? x.r < y.r : x.r > y.r;
}
inline int cmp2(node a, node b) { return a.ID < b.ID; }
vector<int> vec;
inline void modify(int x, int add) {
  kind[ans[x]] += add;
  if (kind[ans[x]] == 1 && vis[ans[x]] == 0) {
    vec.push_back(ans[x]);
    vis[ans[x]] = 1;
  }
}
inline void Read(int &x) {
  char c = getchar();
  x = 0;
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
inline void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a > 9) Out(a / 10);
  putchar(a % 10 + '0');
}
int main() {
  int n, m;
  Read(n);
  sum = 0;
  b = sqrt(n);
  memset(kind, 0, sizeof(kind));
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    Read(ans[i]);
  }
  Read(m);
  for (int i = 1; i <= m; i++) {
    Read(q[i].l);
    Read(q[i].r);
    q[i].ID = i;
  }
  sort(q + 1, q + 1 + m, cmp);
  int l = 1, r = 0;
  vec.push_back(0);
  kind[0] = 1;
  for (int i = 1; i <= m; i++) {
    while (l > q[i].l) {
      modify(--l, 1);
    }
    while (l < q[i].l) {
      modify(l++, -1);
    }
    while (r < q[i].r) {
      modify(++r, 1);
    }
    while (r > q[i].r) {
      modify(r--, -1);
    }
    while (kind[vec.back()] != 1) {
      vis[vec.back()] = 0;
      vec.pop_back();
    }
    aaaas[q[i].ID] = vec.back();
  }
  for (int i = 1; i <= m; i++) {
    Out(aaaas[i]);
    putchar('\n');
  }
  return 0;
}
