#include <bits/stdc++.h>
using namespace std;
int main() {
  int y;
  scanf("%d", &y);
  while (y--) {
    long long int l, v, a, b, k = 0, sum = 0, bq, aq;
    scanf("%lld%lld%lld%lld", &l, &v, &a, &b);
    if (v > b) {
      sum = l / v;
      printf("%lld\n", sum);
    } else {
      sum = l / v;
      if (v < a) {
        if (a % v == 0)
          aq = a / v - 1;
        else
          aq = a / v;
        bq = b / v;
        k = bq - aq;
        printf("%lld\n", sum - k);
      } else {
        bq = b / v;
        k = bq;
        printf("%lld\n", sum - k);
      }
    }
  }
  return 0;
}
