#include <bits/stdc++.h>
using namespace std;
const int sz = 800;
int arr[555555], seg[555555], ans[555555], ch[555555], nu[888];
vector<pair<int, pair<int, int> > > inf[888];
bool tmr(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  return a.second.first < b.second.first;
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int e = 0; e < n; e++) scanf("%d", &arr[e]);
  int q;
  scanf("%d", &q);
  for (int e = 0; e < q; e++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    inf[(l / sz)].push_back(make_pair(l, make_pair(r, e)));
  }
  for (int e = 0; e < 888; e++) sort(inf[e].begin(), inf[e].end(), tmr);
  for (int e = 0; e < 888; e++) {
    if ((int)inf[e].size() == 0) continue;
    memset(seg, 0, sizeof(seg));
    memset(nu, 0, sizeof(nu));
    memset(ch, 0, sizeof(ch));
    int ll = inf[e][0].first, rr = inf[e][0].second.first,
        wh = inf[e][0].second.second;
    for (int p = ll; p <= rr; p++) {
      seg[arr[p]]++;
      if (seg[arr[p]] == 1) {
        nu[arr[p] / sz]++;
      } else if (seg[arr[p]] == 2) {
        nu[arr[p] / sz]--;
      }
    }
    ans[wh] = 0;
    for (int p = 0; p < sz; p++) {
      if (nu[p]) {
        for (int q = p * sz; q < min((p + 1) * sz, n + 1); q++) {
          if (seg[q] == 1) {
            ans[wh] = q;
            break;
          }
        }
        if (ans[wh] != 0) break;
      }
    }
    for (int q = 1; q < inf[e].size(); q++) {
      int ll2 = inf[e][q].first, rr2 = inf[e][q].second.first,
          wh2 = inf[e][q].second.second;
      if (ll2 < ll) {
        for (int r = ll - 1; r >= ll2; r--) {
          seg[arr[r]]++;
          if (seg[arr[r]] == 1) {
            nu[arr[r] / sz]++;
          } else if (seg[arr[r]] == 2) {
            nu[arr[r] / sz]--;
          }
        }
      } else {
        for (int r = ll; r < ll2; r++) {
          seg[arr[r]]--;
          if (seg[arr[r]] == 1) {
            nu[arr[r] / sz]++;
          } else if (seg[arr[r]] == 0) {
            nu[arr[r] / sz]--;
          }
        }
      }
      for (int r = rr + 1; r <= rr2; r++) {
        seg[arr[r]]++;
        if (seg[arr[r]] == 1) {
          nu[arr[r] / sz]++;
        } else if (seg[arr[r]] == 2) {
          nu[arr[r] / sz]--;
        }
      }
      ll = ll2;
      rr = rr2;
      ans[wh2] = 0;
      for (int p = 0; p < sz; p++) {
        if (nu[p]) {
          for (int q = p * sz; q < min((p + 1) * sz, n + 1); q++) {
            if (seg[q] == 1) {
              ans[wh2] = q;
              break;
            }
          }
          if (ans[wh2] != 0) break;
        }
      }
    }
  }
  for (int e = 0; e < q; e++) printf("%d\n", ans[e]);
  return 0;
}
