#include #include using namespace std; typedef long long ll; const int MOD = 998244353; const int MAXN = 100005; ll ksm(ll a,ll b) { ll t = 1; while(b){ if(b&1) t = t*a%MOD; a = a*a%MOD; b >>= 1; } return t%MOD; } int a[MAXN]; /* 1 4 1 1 2 3 */ int main() { int t; scanf("%d",&t); while(t--) { int n,k; scanf("%d %d",&n,&k); for(int i = 1;i <= n;i++) scanf("%d",&a[i]); sort(a + 1,a + n + 1); ll le = a[1] - k,ri = a[1] + k; ll ans = ri - le + 1; for(int i = 2;i <= n;i++) { ll nowle = a[i] - k; ll nowri = a[i] + k; if(nowle > ri) ans += nowri - nowle + 1,ri = nowri; else if(nowri <= ri) continue; else { ans += nowri - ri; ri = nowri; } } printf("%lld\n",min(ans,1ll*n)); } return 0; }