#include <bits/stdc++.h>
using namespace std;
int a[500005];
set<int> s;
int num[500005];
struct node {
  int l, r, pos, id;
  node() {}
  node(int l, int r, int pos, int id) : l(l), r(r), pos(pos), id(id) {}
};
node f[500005];
bool com(node a, node b) {
  if (a.id != b.id) return a.l < b.l;
  if (b.id & 1) return a.r < b.r;
  return a.r > b.r;
}
int c[500005], cn[500005];
int cnt;
void add(int x) {
  x = a[x];
  if (num[x] == 0) {
    c[++cnt] = x;
    cn[x] = cnt;
  }
  if (num[x] == 1) {
    c[cn[x]] = c[cnt];
    cn[c[cnt]] = cn[x];
    c[cnt] = 0;
    cn[x] = 0;
    cnt--;
  }
  num[x]++;
}
void del(int x) {
  x = a[x];
  if (num[x] == 2) {
    c[++cnt] = x;
    cn[x] = cnt;
  }
  if (num[x] == 1) {
    c[cn[x]] = c[cnt];
    cn[c[cnt]] = cn[x];
    c[cnt] = 0;
    cn[x] = 0;
    cnt--;
  }
  num[x]--;
}
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void read(int& x) {
  x = 0;
  char c = gc();
  while (c < '0' || c > '9') c = gc();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = gc();
  }
}
void print(int x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
int ans[500005];
int n, m;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  read(m);
  int a, b;
  int siz = sqrt(n);
  for (int i = 1; i <= m; i++) {
    read(a);
    read(b);
    f[i] = node(a, b, i, (a) / siz + 1);
  }
  sort(f + 1, f + 1 + m, com);
  int l = 1, r = 0;
  for (int i = 1; i <= m; i++) {
    int L = f[i].l, R = f[i].r;
    while (l < L) del(l++);
    while (l > L) add(--l);
    while (r < R) add(++r);
    while (r > R) del(r--);
    ans[f[i].pos] = c[1];
  }
  for (int i = 1; i <= m; i++) {
    print(ans[i]);
    putchar('\n');
  }
  return 0;
}
