#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b, c, d;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    c -= 1;
    long long tmp = a / b, e = c / b, f = d / b;
    long long hasil = tmp - f + e;
    cout << hasil << endl;
  }
}
