#include <bits/stdc++.h>
using namespace std;
int main() {
  int L, p, l, r, ts;
  scanf("%d", &ts);
  while (ts--) {
    scanf("%d %d %d %d", &L, &p, &l, &r);
    int tot = (l - 1) / p + (L / p) - (r / p);
    printf("%d\n", tot);
  }
  return 0;
}
