/*
  [BAPC'07] SPACE
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <vector>

inline long long sqr (int x) { return x*x; }
int main () {

  int runs;
  cin>>runs;
  while (runs--) {

    int N,K;
    cin>>N>>K;
    
    vector<pair<int,int> > p(N);
    for (int i=0; i<N; i++)
      cin>>p[i].first>>p[i].second;

    sort(p.begin(),p.end());

    vector<int> x(N),y(N);
    for (int i=0; i<N; i++)
      x[i]=p[i].first, y[i]=p[i].second;

    int res=0;
    
    vector<int> from(K,0);
    for (int i=0; i<N; i++)
      for (int dx=0; dx<K; dx++) {
	while (x[from[dx]]<x[i]-dx) from[dx]++;
	while (x[from[dx]]==x[i]-dx && y[from[dx]]<y[i]-K) from[dx]++;

	for (int j=from[dx]; j<i && x[j]==x[i]-dx && y[j]<y[i]+K; j++)
	  if (sqr(x[j]-x[i])+sqr(y[j]-y[i]) < sqr(K)) res++;
      }

    cout<<res<<endl;
  }
  
  return 0;
}
