#include <bits/stdc++.h>
int main(int argc, char **argv) {
  int t, k;
  scanf("%d", &t);
  for (k = 0; k < t; k++) {
    int a, b, x, y, z = 0;
    scanf("%d %d %d %d", &a, &b, &x, &y);
    printf("%d\n", a / b - y / b + (x - 1) / b);
  }
  return 0;
}
