#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ri register signed #define RI register signed #define cf cout.flush(); #define lson (rt<<1|1) #define rson (rt<<1) #define lson1 (rt1<<1) #define rson1 (rt1<<1|1) #define lson2 (rt2<<1) #define rson2 (rt2<<1|1) #define mid ((l+r)>>1) #define mid1 ((l1+r1)>>1) #define mid2 ((l2+r2)>>1) #define mes(x) memset(x,0,sizeof x) typedef long long LL; typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef pairP; typedef pair PP; typedef pair PPll; //#define int long long //#define double long double #define ri register signed #define il inline #define deb(...) logger(#__VA_ARGS__,__VA_ARGS__) template void logger(string vars, Args&&... values) { cout << vars << " = "; string delim = ""; //(..., (cout << delim << values, delim = ", ")); } inline string toString(int x) { string ans = ""; bool negtive = x < 0; x = abs(x); while (x)ans.push_back(x % 10 + '0'), x /= 10; if (ans.size() == 0)ans = "0"; if (negtive)ans.push_back('-'); for (int i = 0; i < ans.size() / 2; i++) swap(ans[i], ans[ans.size() - 1 - i]); return ans; } inline int toInt(const string&str) { int ans = 0; bool negtive = str[0] == '-'; for (int i = negtive; i < str.size(); i++) ans = ans * 10 + str[i] - '0'; if (negtive)ans *= -1; return ans; } inline int gcd(int x, int y) { return x ? gcd(y%x, x) : y; } ll exgcd(ll a, LL b, LL &x, LL &y) { LL d = a; if (b == 0) x = 1, y = 0; else { d = exgcd(b, a%b, y, x), y -= a / b * x; } return d; } const int mod = 998244353; inline int read() { int ans = 0; char last = ' ', ch = getchar(); while (!(ch >= '0' && ch <= '9'))last = ch, ch = getchar(); while (ch >= '0' && ch <= '9')ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar(); return ans; } inline int QPow(ll a, ll b) { LL ans = 1; if (b < 0)return 0; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } inline int QPow(LL a, LL b, const int&mod) { LL ans = 1; while (b) { if (b & 1)ans = ans * a%mod; a = a * a%mod; b >>= 1; } return ans; } const double PI = 3.141592653589793115997963468544185161590576171875; const double e = 2.718281828459045; void ask(int x) { cout << '?' << ' ' << x << endl; cf; } void decide(int x) { cout << "! " << x << endl; cf; } short _min(short a, short b) { return a < b ? a : b; } const int inf = 1+(1 << 30); const int inf2 = 10000; const double eps = 1e-10; int db_cmp(double x, double y) { if (fabs(x - y) < eps)return 0; if (x > y)return 1; return -1; } double distance(P p1, P p2) { return sqrt((p1.first - p2.first)*(p1.first - p2.first) + (p2.second - p1.second)*(p2.second - p1.second)); } const int maxn = 200002; int arr[maxn]; unordered_mapmp; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //getInv(); //init(); signed t, n, k, m; cin >> t; while (t--) { int n, k; mp.clear(); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + 1 + n); int ptr = arr[1] - k; int ans = 0; for (int i = 1; i <= n; i++) { if (ptr < arr[i] - k)ptr = arr[i] - k; while (ptr <= arr[i] + k && mp.count(ptr) != 0) ptr++; if (ptr == arr[i] + k + 1) ; else mp[ptr] = 1, ans++; } cout << ans << '\n'; mp.clear(); } //system("pause"); return 0; }