#include #include #define ll long long using namespace std; const int inf = 1e9; const int N = 300007; const int mod = 998244353; const double eps = 1e-6; const double pi = acos(-1.0); #define pa pair #define rep(i, a, b) for(int i=(a);i<=(b);++i) #define per(i, a, b) for(int i=(a);i>=(b);--i) #define ms(a, b) memset(a, b, sizeof a) inline int read(){ int x; scanf("%d", &x); return x; } struct Node{ int val, num; }; int T, n, m; int a[N]; mapmp; vectorve; void solve() { ve.clear(); mp.clear(); n = read(), m = read(); int ans = n; rep(i, 1, n){ a[i] = read(); if(!mp.count(a[i]))mp[a[i]] = 1; else mp[a[i]]++; } for(auto v : mp)ve.push_back({v.first, v.second}); int l = ve[0].val - m - 1; for(auto v : ve){ int l1 = v.val - m, r1 = v.val + m; if(l1 <= l)l1 = l + 1; if(r1 - l1 + 1 >= v.num)l = l1 + v.num - 1; else if(r1 - l1 >= 0){ l = r1; ans -= (v.num - (r1 - l1 + 1)); } } cout << ans << "\n"; } signed main() { T = read(); while(T--)solve(); }