#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e;
int main() {
  cin >> a;
  while (a--) {
    cin >> b >> c >> d >> e;
    if (d > b) {
      cout << b / c << endl;
      continue;
    }
    d--;
    cout << b / c - ((min(e, b) / c) - (d / c)) << endl;
  }
}
