#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > AdjList;
priority_queue<pair<int, pair<int, int> > > Edgelist;
long long int n, m;
int i, t, k, l, j;
int main() {
  cin >> t;
  while (t--) {
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;
    c = (c / b) + (c % b == 0 ? 0 : 1);
    d = (d / b);
    cout << a / b - (d - c + 1) << endl;
  }
}
