/**
 * Behdad Hosseini, mailto:acm(AT)behdadh(DOT)net(replace AT and DOT), www.behdadh.net
 * Date: 7 nov 2003
 * A sample code for ACM problem : A (Grandpa's Other Estate) from 2002 Asia - Tehran
 */
#include <fstream.h>

#define MAX 200

void main()
{
	ifstream in("a.in");
	ofstream out("a.out");

	int x0[4] = { -1,  0, -1,  0 };
	int x1[4] = {  0,  1,  0,  1 };
	int y0[4] = {  0,  0, -1, -1 };
	int y1[4] = {  1,  1,  0,  0 };

	
	int tc;
	in >> tc;

	while(tc--)
	{
		int N,R;
		in >> N >> R;

		long x[MAX], y[MAX];

		for (int i=0;i<N; i++)
			in >> x[i] >> y[i];

		int max = -1, trees;
		for (i=0;i<N;i++)
			for (int j=0; j<4; j++)
			{
				trees = 0;
				for( int k=0; k<N; k++)
					if ( ( x[k] >= x[i] +x0[j]*R )  && ( x[k]<= x[i] +x1[j]*R ) &&
						 ( y[k] >= y[i] +y0[j]*R )  && ( y[k]<= y[i] +y1[j]*R )  ) 
						 trees ++;
				if (trees > max)
					max = trees;
			}

		out << max << endl;
	}

	out.close();
	in.close();
}


