#include typedef long long ll; typedef std::pair pii; const int N = 1e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-9; int a[N]; std::vector v; std::unordered_map mp1; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif std::ios::sync_with_stdio(0); std::cin.tie(0); int t; std::cin >> t; while(t--) { mp1.clear(); v.clear(); int n, k; std::cin >> n >> k; for(int i = 0; i< n; i++) { std::cin >> a[i]; } std::sort(a, a + n); int cnt = 1; for(int i = 1; i < n; i++) { if(a[i] == a[i - 1]) { cnt ++; } else { v.push_back({a[i - 1], cnt}); cnt = 1; } } v.push_back({a[n - 1],cnt}); int l = -inf; for(auto o :v) { int x = o.first, y = o.second; //std::cout << x << ' ' << y << std::endl; for(int i = std::max(x - k, l); i <= x + k; i ++) { if(y == 0) break; if(!mp1.count(i)) mp1[i] = 1, y--, l = std::max(l, i); } } std::cout << mp1.size() << std::endl; } }