#include <bits/stdc++.h>
using namespace std;
const int block = 710;
int n, m, a[1000000], bo[1000000], top, sta[1000000], pos[1000000],
    ans[1000000];
struct arr {
  int l, r, num;
} ask[1000000];
bool cmp(arr x, arr y) {
  if ((x.l - 1) / block == (y.l - 1) / block) {
    if (((x.l - 1) / block) & 1) return x.r > y.r;
    return x.r < y.r;
  }
  return x.l < y.l;
}
void add(int x) {
  sta[++top] = x;
  pos[x] = top;
}
void del(int x) {
  swap(pos[x], pos[sta[top]]);
  swap(sta[top], sta[pos[sta[top]]]);
  sta[top--] = pos[x] = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &ask[i].l, &ask[i].r);
    ask[i].num = i;
  }
  sort(ask + 1, ask + m + 1, cmp);
  int l = 1, r = 0;
  for (int i = 1; i <= m; i++) {
    while (l < ask[i].l) {
      --bo[a[l]];
      if (!bo[a[l]]) del(a[l]);
      if (bo[a[l]] == 1) add(a[l]);
      ++l;
    }
    while (l > ask[i].l) {
      --l;
      if (!bo[a[l]]) add(a[l]);
      if (bo[a[l]] == 1) del(a[l]);
      ++bo[a[l]];
    }
    while (r < ask[i].r) {
      ++r;
      if (!bo[a[r]]) add(a[r]);
      if (bo[a[r]] == 1) del(a[r]);
      ++bo[a[r]];
    }
    while (r > ask[i].r) {
      --bo[a[r]];
      if (!bo[a[r]]) del(a[r]);
      if (bo[a[r]] == 1) add(a[r]);
      --r;
    }
    ans[ask[i].num] = sta[top];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
