#include #define For(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; int main() { int R, n; cin >> R >> n; vector a(n); rep(i, n) { cin >> a[i]; } sort(ALL(a)); int q; cin >> q; while (q--) { int l, r; cin >> l >> r; int l_sho = l / R, l_amari = l % R; int r_sho = r / R, r_amari = r % R; int il = lower_bound(ALL(a), l_amari) - a.begin(); int ir = upper_bound(ALL(a), r_amari) - a.begin(); if (l_sho == r_sho) { cout << ir - il << endl; } else { int ans = 0; ans += n - il; ans += n * (r_sho - (l_sho + 1)); ans += ir; cout << ans << endl; } } }