#include <bits/stdc++.h>
using namespace std;
int T;
int len, later, L, R;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d%d", &len, &later, &L, &R);
    int ans1 = (L - 1) / later;
    int ans2 = 0;
    int tmp = 0;
    int tmp2 = R / later;
    for (int i = tmp2; i * later <= len; i++) {
      tmp = i * later;
      if (tmp > R) {
        ans2++;
        break;
      }
    }
    ans2 += (len - tmp) / later;
    if (later <= len)
      printf("%d\n", ans1 + ans2);
    else
      printf("0\n");
  }
}
