#include #include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int32_t R, N, i; cin >> R >> N; vector A(N); for (i = 0; i != N; ++i) cin >> A[i]; int16_t Q; cin >> Q; vector l(Q), r(Q); for (i = 0; i != Q; ++i) cin >> l[i] >> r[i]; for (i = 0; i != Q; ++i) cout << (r[i] / R * N + (upper_bound(A.begin(), A.end(), r[i] % R) - A.begin()) - (l[i] - 1) / R * N - (upper_bound(A.begin(), A.end(), (l[i] - 1) % R) - A.begin())) << '\n'; return 0; }