#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long l, r, n, m;
    cin >> n >> m >> l >> r;
    cout << (n / m) - (((r) / m) - ((l - 1) / m)) << endl;
  }
  return 0;
}
