
import java.lang.*;
import java.io.*;

/**
 * Created by IntelliJ IDEA.
 * Behdad Hosseini, acm@behdadh.net, behdadh.net
 * Date: May 9, 2005
 * A sample code for ACM problem :  A (Grandpa's Other Estate) from 2002 Asia - Tehran
 */
public class A {

    public static final String file = "a";
    public static StreamTokenizer in;
    public static PrintStream out;

    public static String readString() throws IOException {
        in.nextToken();
        return  in.sval;
        }

    public static double readDouble() throws IOException {
            return Double.parseDouble(readString()) ;
        }

    public static int readInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }


    public static boolean inside(int x, int y, int x0, int x1, int y0, int y1) {
        return (x>=x0 && x<=x1 && y>=y0 && y<=y1);
    }

    public static void main(String[] args) throws IOException {

        in = new StreamTokenizer(new FileReader(file + ".in") );
        out = new PrintStream(file + ".out");

        int tc = readInt();
        while( (tc--)  != 0) {
            // begin of test case

            // read input for this case
            int n = readInt();
            int r = readInt();
            int[][] trees = new int[n][2];
            for (int i = 0; i < n; i++) {
                trees[i][0]= readInt();
                trees[i][1]= readInt();
            }

            // solve it
            int max = 0;
            for (int i = 0; i < n; i++) {
                int x = trees[i][0];
                int y = trees[i][1];

                //upleft
                int found = 0;
                for (int j = 0; j < n; j++)
                    if (inside(trees[j][0], trees[j][1], x-r, x, y-r, y)) found ++;
                if (found > max )
                    max = found;

                //upright
                found = 0;
                for (int j = 0; j < n; j++)
                    if (inside(trees[j][0], trees[j][1], x, x+r,  y-r, y)) found ++;
                if (found > max )
                    max = found;

                //downleft
                found = 0;
                for (int j = 0; j < n; j++)
                    if (inside(trees[j][0], trees[j][1], x-r, x,  y, y+r)) found ++;
                if (found > max )
                    max = found;

                //downright
                found = 0;
                for (int j = 0; j < n; j++)
                    if (inside(trees[j][0], trees[j][1], x, x+r,  y, y+r)) found ++;
                if (found > max )
                    max = found;

            }

            // write the result
            out.println(max);
        }

        out.close();
    }

}

