#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, v1, v2, v3;
string s1, s2, s3;
int main() {
  long long int a[100001] = {0}, b[100001], c = 0, d = 0, e, f, i, j, k = 0,
                l = 0, m, n, p = 0, q, t, ct = 0, ct1 = 0, ct2 = 0, ck = 0,
                ck1 = 0, ck2 = 0, ln, ln1, start, end, mid;
  long long int a1 = 0, a2 = 0, a3 = 0, a4 = 0, sum = 0, sum1 = 0, max1, max2,
                min1, min2;
  double x, y, z;
  char s[1101], st[1001], ch, ch1, ch2;
  cin >> n;
  for (i = 0; i < n; i++) {
    k = 0;
    cin >> c >> d >> e >> f;
    k = c / d;
    p = e / d;
    q = f / d;
    if (e % d == 0) {
      k = k - 1 - (q - p);
    } else
      k = k - (q - p);
    cout << k << endl;
  }
  return 0;
}
