//打注释的是我的代码,一直超时,别人三行代码顶我一坨,同是尺取法,为什么 我的复杂度就这么高呢?
#include <cstdio>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
const int MAX_N = 100010;
int arr[MAX_N];
int main()
{
int n, s;
long long ans;
int T;
scanf("%d",&T);
while(T--)
{
ans=0;
scanf("%d%d", &n, &s);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
int l = 0, r = 0;
stable_sort(arr,arr+n);
int sum = 0;
/* while (true)
{
if(r==n) break;
while(1)
{
++r;
if(r==n) break;
if( arr[r]-arr[l]<=s)
ans++;
}
l++;
r=l;
}*/
int j;
for(int i = 0,j = 0; i < n; i++)
{
while(j + 1 < n && arr[j+1] - arr[i] <= s) j++;
ans += j - i;
}
printf("%lld
", ans);
}
return 0;
}