#include #include using namespace std; const int N=1e5+10; int a[N]; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k; for(int i=1;i<=n;i++) scanf("%d",a+i); sort(a+1,a+n+1); long long use=0,last=-1e10; long long L=1,R,LEN; while(L<=n) { R=L; while(R+1<=n&&a[R+1]==a[L]) R++; long long l,r,len; l=max(last,1ll*a[L]-k); r=1ll*a[L]+k; LEN=R-L+1; if(r-l+1>=LEN){ use+=LEN; last=l+LEN; } else use+=r-l+1,last=r+1; L=R+1; } printf("%lld\n",use); } }