#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct GT_cls //创建函数对象
{
public:
GT_cls(int t=):a(t){}
bool operator()(int x)
{
return x>a;
}
private:
int a;
};
int main()
{
int T,N,M;
cin>>T;
for(int i=; i<T; i++)
{
cin>>N>>M;
vector<int> eigenval(N);
for(int j=; j<N; j++)
cin>>eigenval[j];
sort(eigenval.begin(), eigenval.end()); //从小到大排序
int max=;
for(int j=; j<N-; j++)
{
vector<int>::iterator it = find_if(eigenval.begin()+j, eigenval.end(), GT_cls(eigenval[j]+M)); //所选取的几种化合物只要满足最小特征值和最大特征值不大于阈值M即可
unsigned num = it-(eigenval.begin()+j);
if(num>max)
max = num;
}
cout<<max<<endl;
}
return ;
}