#include <bits/stdc++.h>
namespace IO {
char ch = '\n';
template <class T>
inline T ReadInt() {
  T x(0);
  bool f(1);
  while (ch < '0' || '9' < ch) {
    if (ch == '-') {
      f = 0;
    }
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return f ? x : -x;
}
template <class T>
inline T ReadUInt() {
  T x(0);
  while (ch < '0' || '9' < ch) {
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x;
}
inline double ReadDouble() {
  long long int_num = ReadInt<long long>();
  if (ch == '.') {
    double pow10 = 1, result = int_num;
    ch = getchar();
    while ('0' <= ch && ch <= '9') {
      pow10 /= 10.0;
      result += pow10 * (ch ^ 48);
      ch = getchar();
    }
    return result;
  } else {
    return (double)int_num;
  }
}
inline void ReadT(int &x) { x = ReadInt<int>(); }
inline void ReadT(long long &x) { x = ReadInt<long long>(); }
inline void ReadT(bool &x) { x = ReadUInt<bool>(); }
inline void ReadT(unsigned int &x) { x = ReadUInt<unsigned int>(); }
inline void ReadT(unsigned long long &x) { x = ReadUInt<unsigned long long>(); }
inline void ReadT(double &x) { x = ReadDouble(); }
inline void ReadT(char &s) {
  for (; isspace(ch) && (~ch); ch = getchar())
    ;
  s = ch;
  ch = '\n';
}
inline void ReadT(char *s) {
  int len(0);
  for (; isspace(ch) && (~ch); ch = getchar())
    ;
  for (; !isspace(ch) && (~ch); ch = getchar()) {
    s[len++] = ch;
  }
  s[len] = '\0';
  ch = '\n';
}
template <typename T>
inline void Read(T &t) {
  ReadT(t);
}
template <typename T, typename... Args>
void Read(T &t, Args &...args) {
  ReadT(t);
  Read(args...);
}
template <typename T>
void WriteInt(T x) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (9 < x) {
    WriteInt(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename T>
void WriteUInt(T x) {
  if (9 < x) {
    WriteInt(x / 10);
  }
  putchar(x % 10 + '0');
}
void WriteDouble(long double x, int len) {
  WriteInt((long long)x);
  if (len) {
    x -= (int)x;
    putchar('.');
    if (!x) {
      while (len--) {
        putchar(48);
      }
      return;
    }
    while (len--) {
      x *= 10;
    }
    WriteInt((long long)round(x));
  }
}
template <typename T>
inline void WriteT(T x);
template <>
inline void WriteT<int>(int x) {
  WriteInt<int>(x);
}
template <>
inline void WriteT<long long>(long long x) {
  WriteInt<long long>(x);
}
template <>
inline void WriteT<bool>(bool x) {
  WriteUInt<bool>(x);
}
template <>
inline void WriteT<unsigned int>(unsigned int x) {
  WriteUInt<unsigned int>(x);
}
template <>
inline void WriteT<unsigned long long>(unsigned long long x) {
  WriteUInt<unsigned long long>(x);
}
template <>
inline void WriteT<double>(double x) {
  WriteDouble(x, 6);
}
template <>
inline void WriteT<char *>(char *s) {
  int len(strlen(s));
  while (len--) {
    putchar(*s++);
  }
}
template <>
inline void WriteT<const char *>(const char *s) {
  while (*s) {
    putchar(*s++);
  }
}
template <>
inline void WriteT<char>(char x) {
  putchar(x);
}
template <typename T>
inline void Write(T t) {
  WriteT(t);
}
template <typename T, typename... Args>
void Write(T t, Args... args) {
  WriteT(t);
  Write(args...);
}
template <typename T>
inline void Writeln(T t) {
  WriteT(t);
  puts("");
}
template <typename T, typename... Args>
inline void Writeln(T t, Args... args) {
  WriteT(t);
  Write(args...);
  puts("");
}
inline void Writeln() { puts(""); }
const char NUMBER[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                         '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                         'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                         'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
template <typename T>
void WriteK(T x, int p) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (p <= x) {
    WriteK(x / p, p);
  }
  putchar(NUMBER[x % p]);
}
}  // namespace IO
using namespace IO;
using namespace std;
const int MAXN = 5e5 + 5;
int n, m;
int arr[MAXN];
namespace SGT {
struct SegmentTree {
  int max;
} sgt[MAXN << 2];
void PushUp(int now) {
  sgt[now].max = max(sgt[(now << 1)].max, sgt[(now << 1 | 1)].max);
}
void Updata(int place, int val, int now = 1, int left = 0, int right = n) {
  if (place < left || right < place) {
    return;
  }
  if (left == right) {
    sgt[now].max = val;
    return;
  }
  Updata(place, val, (now << 1), left, ((left + right) >> 1));
  Updata(place, val, (now << 1 | 1), ((left + right) >> 1) + 1, right);
  PushUp(now);
}
int Query(int now_right, int now = 1, int left = 0, int right = n) {
  if (now_right < left || sgt[now].max <= now_right) {
    return 0;
  }
  if (left == right) {
    return left;
  }
  int result = 0;
  if (now_right < sgt[(now << 1 | 1)].max &&
      ((left + right) >> 1) + 1 <= now_right) {
    result = Query(now_right, (now << 1 | 1), ((left + right) >> 1) + 1, right);
    if (result) {
      return result;
    }
  }
  return Query(now_right, (now << 1), left, ((left + right) >> 1));
}
}  // namespace SGT
struct Query {
  int left, right, id;
  bool operator<(const Query a) const { return left < a.left; }
} q[MAXN];
int answer[MAXN];
int nex[MAXN];
int last[MAXN];
int main() {
  Read(n);
  for (int i = 1; i <= n; ++i) {
    Read(arr[i]);
  }
  for (int i = 1; i <= 5e5; ++i) {
    last[arr[i]] = n + 1;
  }
  for (int i = n; 1 <= i; --i) {
    nex[i] = last[arr[i]];
    last[arr[i]] = i;
  }
  Read(m);
  for (int i = 1; i <= m; ++i) {
    Read(q[i].left, q[i].right);
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
  for (int i = 1; i <= 5e5; ++i) {
    if (last[i] <= n) {
      SGT::Updata(last[i], nex[last[i]]);
    }
  }
  int now = 1;
  for (int i = 1; i <= n; ++i) {
    while (q[now].left == i) {
      answer[q[now].id] = SGT::Query(q[now].right);
      if (answer[q[now].id] < i) {
        answer[q[now].id] = 0;
      }
      ++now;
    }
    SGT::Updata(nex[i], nex[nex[i]]);
  }
  for (int i = 1; i <= m; ++i) {
    Writeln(arr[answer[i]]);
  }
  return 0;
}
