// Sat Nov 16 09:57:41 2024 // Problem "No.2961 Shiny Monster Master" in contest "unknown_contest" #include #include #pragma GCC optimize("O3") #include #ifdef NOJUDGE #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define debug(...) #endif using namespace std; typedef long long int ll; const ll MOD = 1000000007; const ll MOD2 = 998244353; inline void solve() { ll n, R; scanf("%lld %lld", &R, &n); vector a(n); for (ll i = 0; i < n; i++) { scanf("%lld", &a[i]); } sort(a.begin(), a.end()); auto count = [&](ll z) -> ll { ll x = z / R * n; ll y = lower_bound(a.begin(), a.end(), z % R) - a.begin(); debug("Count up to %lld: %lld + %lld = %lld\n", n, x, y, x + y); return x + y; }; auto query = [&](ll l, ll r) -> ll { return count(r + 1) - count(l); }; ll q; scanf("%lld", &q); for (ll i = 0; i < q; i++) { ll l, r; scanf("%lld %lld", &l, &r); printf("%lld\n", query(l, r)); } } #define yukicoder int main() { #if defined(Codeforces) || defined(CodeChef) ll t; scanf("%lld", &t); for (int i = 0; i < t; i++) { solve(); } #else solve(); #endif }