#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int x, n; cin >> x >> n; vector a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); int q; cin >> q; while (q--) { int l, r; cin >> l >> r; ll ans = 0; if (l / x == r / x) { ans += upper_bound(a.begin(), a.end(), r % x) - lower_bound(a.begin(), a.end(), l % x); } else { ans += ((r / x) - ((l + x - 1) / x)) * n; ans += upper_bound(a.begin(), a.end(), r % x) - a.begin(); ans += a.end() - lower_bound(a.begin(), a.end(), l % x); } cout << ans << endl; } return 0; }