#include <bits/stdc++.h> using namespace std; using ll = long long; int n, k, ans = 0; vector<int> a(3e5, 0); set<pair<int, int>> s; set<pair<int, int>> s2; void reset() { ans = 0; s.clear(); s2.clear(); s2.insert({1e9, 1e9}); } void be(int i) { s.insert({a[i], i}); s2.insert({-a[i], i}); } void kii(int i) { s.erase({a[i], i}); s2.erase({-a[i], i}); } bool f() { if (!s.size()) return false; int x = (*s.begin()).second; kii(x); if (a[x] > k || !s.size()) return true; int y = (*(s2.upper_bound({a[x] - k, 1e9}))).second; if (y < 1e9) kii(y); if (!s.size()) return true; int z = (*s2.begin()).second; kii(z); return true; } void solve() { cin >> n >> k; reset(); for (int i = 0; i < n; i++) { cin >> a[i]; be(i); } while (f()){ ans++; // for (auto p: s) cout << p.first << " "; // cout << endl; } cout << ans - 1 << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) solve(); } /* 1 8 25 4 5 18 3 17 17 18 14 */