import java.util.*;

public class erikjan {
	static Scanner in=new Scanner(System.in);

	public static void main(String[] args) {
		int n=in.nextInt();
		for(int i=1;i<=n;++i) run();
	}
	
	public static void run() {
		int n=in.nextInt(); int k=in.nextInt();
		P[] p=new P[n]; for(int i=0;i<n;++i) { p[i]=new P(); p[i].x=in.nextInt(); p[i].y=in.nextInt(); }
		Arrays.sort(p);
		long ret=0;
		for(int j=0;j<k;++j) {
			int l=0,h=0,maxdx=0; while(j*j+(maxdx+1)*(maxdx+1)<k*k) ++maxdx;
			for(int i=0;i<n;++i) {
				while(l<i&&p[l].y<p[i].y-j) ++l;
				while(l<i&&p[l].y==p[i].y-j&&p[l].x<p[i].x-maxdx) ++l;
				while(h<i&&p[h].y<p[i].y-j) ++h;
				while(h<i&&p[h].y==p[i].y-j&&p[h].x<=p[i].x+maxdx) ++h;
				ret+=h-l;
			}
		}
		System.out.println(ret);
	}
	
	public static class P implements Comparable {
		public int x,y;
		public int compareTo(Object OBJ) {
			P obj=(P)OBJ;
			if(this.y!=obj.y) return this.y<obj.y?-1:+1;
			if(this.x!=obj.x) return this.x<obj.x?-1:+1;
			return 0;
		}
	}
}
