#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n,k,x,mx; cin >> t;
while(t--){
cin >> n >> k;
map<int,int> f;
for(int i=0;i<n;i++){
cin >> x;
f[x]++;
}
auto it = f.begin();
//cout << it->first << endl;
mx = (it->first) + k;
//cout << "1.mx = " << mx << endl;
f[mx]++;
it = f.find(mx);
if(it->second > 1){
cout << it->second << endl;
continue;
}else{
cout << "2.mx = " << mx << endl;
mx--;
while(f.find(mx) == f.end() && mx > 0) mx--;
it = f.find(mx);
f.find(mx) == f.begin() ? cout << "-1\n" : cout << it->second << endl;
}
cout << endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCl7CglpbnQgdCxuLGsseCxteDsJY2luID4+IHQ7Cgl3aGlsZSh0LS0pewoJCWNpbiA+PiBuID4+IGs7CgkJbWFwPGludCxpbnQ+IGY7CgkJZm9yKGludCBpPTA7aTxuO2krKyl7CgkJCWNpbiA+PiB4OwoJCQlmW3hdKys7CgkJfQoJCWF1dG8gaXQgPSBmLmJlZ2luKCk7CgkJLy9jb3V0IDw8IGl0LT5maXJzdCA8PCBlbmRsOwoJCW14ID0gKGl0LT5maXJzdCkgKyBrOwoJCS8vY291dCA8PCAiMS5teCA9ICIgPDwgbXggPDwgZW5kbDsKCQlmW214XSsrOwoJCWl0ID0gZi5maW5kKG14KTsKCQlpZihpdC0+c2Vjb25kID4gMSl7CgkJCWNvdXQgPDwgaXQtPnNlY29uZCA8PCBlbmRsOwoJCQljb250aW51ZTsKCQl9ZWxzZXsKCQkJY291dCA8PCAiMi5teCA9ICIgPDwgbXggPDwgZW5kbDsKCQkJbXgtLTsKCQkJd2hpbGUoZi5maW5kKG14KSA9PSBmLmVuZCgpICYmIG14ID4gMCkgbXgtLTsKCQkJaXQgPSBmLmZpbmQobXgpOwoJCQlmLmZpbmQobXgpID09IGYuYmVnaW4oKSA/IGNvdXQgPDwgIi0xXG4iIDogY291dCA8PCBpdC0+c2Vjb25kIDw8IGVuZGw7IAoJCX0KCQljb3V0IDw8IGVuZGw7CgkJCgl9CglyZXR1cm4gMDsKfQ==