#include #include #include #include #include #include #include #include using namespace std; #define int long long #define endl "\n" #define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n" templateostream & operator<<(ostream &out,vector &v){ for(T i:v)out<istream & operator>>(istream &in,vector &v){ for(T &i:v)in>>i; return in; } void init(); void task(); int32_t main(){ int t=1; init(); cin>>t; while(t--)task(); } void init(){} unordered_mapm; int find(int x){ if(!m[x]){ return x; } return m[x] = find(m[x]); } void task(){ m.clear(); int n,k,temp; cin>>n>>k; vector>a; a.resize(n); for(int i=0;i>temp; a[i].first=temp-k; a[i].second=temp+k; } sort(a.begin(),a.end(), [](pair x, pair y) { if(x.second == y.second) return x.first < y.first; else return x.second < y.second; }); int res = 0; for(int i=0; i < n; i ++) { int d = find(a[i].first); if(d > a[i].second) continue; res++; m[d] = a[i].first; if(m[d + 1]) { m[a[i].first] = m[d + 1]; m[d + 1] = a[i].first; } else { m[a[i].first] = d + 1; } } cout << res << endl; }