#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, a, l, r;
    cin >> n >> a >> l >> r;
    long long up1 = n / a;
    long long lo1 = (a + a - 1) / a;
    long long r1 = up1 - lo1;
    long long up2 = r / a;
    long long lo2 = (l + a - 1) / a;
    long long r2 = up2 - lo2;
    cout << r1 - r2 << endl;
  }
}
