#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a = a / b;
    c = (c - 1) / b;
    d /= b;
    cout << a - (d - c) << endl;
  }
  return 0;
}
