//KZNS
#include <fstream>
#include <algorithm>
using namespace std;
///////////////////
ifstream fin ("diff.in");
ofstream fout ("diff.out");
const int Nmax = 50003;
const int Qmax = 200003;
class QAQ {
public:
int l, r, id;
};
inline bool cmd(QAQ a, QAQ b) {
return a.l < b.l;
}
////---////-------///////---
int N, Q;
QAQ qls[Qmax];
int lst[1000003] = {0};
int nt[Nmax] = {0};
int ed[Qmax] = {0};
int tr[65600] = {0};
//--------------------------
inline int lowbit(int x) {
return x&-x;
}
inline void adin(int x) {
while (x <= N) {
tr[x]++;
x += lowbit(x);
}
}
inline int ck(int l, int r) {
l--;
int a = 0, b = 0;
while (l) {
a += tr[l];
l -= lowbit(l);
}
while (r) {
b += tr[r];
r -= lowbit(r);
}
return b - a;
}
void fir () {
fin >> N;
int a;
for (int i = 1; i <= N; i++) {
fin >> a;
if (lst[a] == 0)
adin(i);
else
nt[lst[a]] = i;
lst[a] = i;
}
fin >> Q;
for (int i = 0; i < Q; i++) {
fin >> qls[i].l >> qls[i].r;
qls[i].id = i;
}
sort(qls, qls+Q, cmd);
}
///////main////////
int main() {
fir();
int i = 1, j = 0;
while (j < Q) {
if (qls[j].l <= i) {
ed[qls[j].id] = ck(qls[j].l, qls[j].r);
j++;
}
else {
if (nt[i])
adin(nt[i]);
i++;
}
}
for (int i = 0; i < Q; i++)
fout << ed[i] << endl;
return 0;
}
//UBWH