#include <cstdio>
int main() {
// [L..R]
cin >> n;
forn(i, n)
cin >> a[i];
sort(a, a + n);
cin >> q;
while (q--) {
cin >> L >> R; // number of x : L <= x <= R
// lower_bound = min i : a[i] >= x
// upper_bound = min i : a[i] > x
cout << upper_bound(a, a + n, R) -
lower_bound(a, a + n, L) << endl;
}
}