import java.util.*;
import java.io.*;

public class cf {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), k = sc.nextInt();
			arr = new Integer[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}
			if (n == 1) {
				pw.println(1);
			}
//			else if (2 * k >= arr[n - 1] - arr[0]) {
//				pw.println(n);
//			}
			else {
				Arrays.sort(arr);
				p2[] ans = new p2[n];
				for (int i = 0; i < y.length; i++) {
					ans[i] = new p2(new pair(i - upper(i, arr[i] - k) + 1, i),
							new pair(lower(i, arr[i] + k) - i + 1, i));
				}
//				pw.println(Arrays.toString(ans));
				int max = 0;
				for (int i = 1; i < ans.length; i++) {
					if (ans[i - 1].x.x > ans[i].x.x) {
						ans[i].x = ans[i - 1].x;
					}
				}
				for (int i = ans.length - 2; i >= 0; i--) {
					if (ans[i + 1].y.x > ans[i].y.x) {
						ans[i].y = ans[i + 1].y;
					}
				}
				for (int i = 0; i < ans.length - 1; i++) {
					max = Math.max(max, ans[i].x.x + ans[i + 1].y.x);
				}
				pw.println(max);
//				pw.println(Arrays.toString(ans));
			}
		}
		pw.close();
	}

	public static class p2 {
		pair x, y;

		public String toString() {
			return x + " " + y;
		}

		public p2(pair x, pair y) {
			this.x = x;
			this.y = y;
		}
	}

	static Integer[] arr;

	static int lower(int s, int x) {
		int start = s, end = arr.length - 1, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				ans = mid;
				start = mid + 1;
			}
		}
		return ans;
	}

	static int upper(int e, int x) {
		int start = 0, end = e, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] < x) {
				start = mid + 1;
			} else {
				ans = mid;
				end = mid - 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int sod(long n) {
		int a = 0;
		while (n > 0) {
			a += n % 10;
			n /= 10;
		}
		return a;
	}

	static PrintWriter pw = new PrintWriter(System.out);

	public static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	public static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class SegmentTree {
		int size;
		int[] st;

		public String toString() {
			return Arrays.toString(st);
		}

		void init(int n) {
			size = 1;
			while (size < n)
				size *= 2;
			st = new int[2 * size];
		}

		void build(int[] arr) {
			build(arr, 0, 0, size);
		}

		void build(int[] arr, int x, int lx, int rx) {
			if (rx - lx == 1) {
				if (lx < arr.length) {
					st[x] = arr[lx];
				}
				return;
			}
			int m = (lx + rx) >> 1;
			build(arr, 2 * x + 1, lx, m);
			build(arr, 2 * x + 2, m, rx);
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		void set(int i, int v) {
			set(i, v, 0, 0, size);
		}

		void set(int i, int v, int x, int l, int r) {
			if (r - l == 1) {
				st[x] = v;
				return;
			}
			int m = (l + r) >> 1;
			if (i < m) {
				set(i, v, 2 * x + 1, l, m);
			} else {
				set(i, v, 2 * x + 2, m, r);
			}
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		long get(int l, int r) {
			return get(l, r + 1, 0, 0, size);
		}

		long get(int l, int r, int x, int lx, int rx) {
			if (lx >= r || rx <= l) {
				return 0;
			} else if (lx >= l && rx <= r) {
				return st[x];
			}
			int m = (lx + rx) >> 1;
			return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
		}

		int find(int idx) {
			return find(idx, 0);
		}

		int find(int idx, int node) {
			if (node >= size - 1) {
				return node - size + 1;
			}
//			pw.print(node + " ");
			if (st[node * 2 + 1] > idx) {
				return find(idx, node * 2 + 1);
			} else {
				return find(idx - st[node * 2 + 1], node * 2 + 2);
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.io.*;

public class cf {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), k = sc.nextInt();
			arr = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}
			Arrays.sort(arr);
			if (n == 1) {
				pw.println(1);
			}
//			else if (2 * k >= arr[n - 1] - arr[0]) {
//				pw.println(n);
//			}
			else {
				pair[] ans = new pair[n];
				for (int i = 0; i < y.length; i++) {
					ans[i] = new pair(i - upper(i, arr[i] - k) + 1, lower(i, arr[i] + k) - i + 1);
				}
//				pw.println(Arrays.toString(ans));
				int max = 0;
				for (int i = 1; i < ans.length; i++) {
					if (ans[i - 1].x > ans[i].x) {
						ans[i].x = ans[i - 1].x;
					}
				}
				for (int i = ans.length - 2; i >= 0; i--) {
					if (ans[i + 1].y > ans[i].y) {
						ans[i].y = ans[i + 1].y;
					}
				}
				for (int i = 0; i < ans.length - 1; i++) {
					max = Math.max(max, ans[i].x + ans[i + 1].y);
				}
				pw.println(max);
//				pw.println(Arrays.toString(ans));
			}
		}
		pw.close();
	}

	static int[] arr;

	static int lower(int s, int x) {
		int start = s, end = arr.length - 1, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				ans = mid;
				start = mid + 1;
			}
		}
		return ans;
	}

	static int upper(int e, int x) {
		int start = 0, end = e, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] < x) {
				start = mid + 1;
			} else {
				ans = mid;
				end = mid - 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int sod(long n) {
		int a = 0;
		while (n > 0) {
			a += n % 10;
			n /= 10;
		}
		return a;
	}

	static PrintWriter pw = new PrintWriter(System.out);

	public static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	public static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class SegmentTree {
		int size;
		int[] st;

		public String toString() {
			return Arrays.toString(st);
		}

		void init(int n) {
			size = 1;
			while (size < n)
				size *= 2;
			st = new int[2 * size];
		}

		void build(int[] arr) {
			build(arr, 0, 0, size);
		}

		void build(int[] arr, int x, int lx, int rx) {
			if (rx - lx == 1) {
				if (lx < arr.length) {
					st[x] = arr[lx];
				}
				return;
			}
			int m = (lx + rx) >> 1;
			build(arr, 2 * x + 1, lx, m);
			build(arr, 2 * x + 2, m, rx);
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		void set(int i, int v) {
			set(i, v, 0, 0, size);
		}

		void set(int i, int v, int x, int l, int r) {
			if (r - l == 1) {
				st[x] = v;
				return;
			}
			int m = (l + r) >> 1;
			if (i < m) {
				set(i, v, 2 * x + 1, l, m);
			} else {
				set(i, v, 2 * x + 2, m, r);
			}
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		long get(int l, int r) {
			return get(l, r + 1, 0, 0, size);
		}

		long get(int l, int r, int x, int lx, int rx) {
			if (lx >= r || rx <= l) {
				return 0;
			} else if (lx >= l && rx <= r) {
				return st[x];
			}
			int m = (lx + rx) >> 1;
			return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
		}

		int find(int idx) {
			return find(idx, 0);
		}

		int find(int idx, int node) {
			if (node >= size - 1) {
				return node - size + 1;
			}
//			pw.print(node + " ");
			if (st[node * 2 + 1] > idx) {
				return find(idx, node * 2 + 1);
			} else {
				return find(idx - st[node * 2 + 1], node * 2 + 2);
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.io.*;

public class cf {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), k = sc.nextInt();
			arr = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}
			if (n == 1) {
				pw.println(1);
			}
//			else if (2 * k >= arr[n - 1] - arr[0]) {
//				pw.println(n);
//			}
			else {
				Arrays.sort(arr);
				pair[] ans = new pair[n];
				int j = 0;
				for (int i = 0; i < ans.length; i++) {
					ans[i] = new pair(0, 0);
				}
				for (int i = 0; i < ans.length; i++) {
					while (arr[i] - arr[j] > k) {
						if (i == j)
							break;
						j++;
					}
					ans[i].x = i - j + 1;
				}
				j = n - 1;
				for (int i = n-1; i >= 0; i--) {
					while (arr[j] - arr[i] > k) {
						if (i == j)
							break;
						j--;
					}
					ans[i].y = j - i + 1;
				}
//				pw.println(Arrays.toString(ans));
				int max = 0;
				for (int i = 1; i < ans.length; i++) {
					if (ans[i - 1].x > ans[i].x) {
						ans[i].x = ans[i - 1].x;
					}
				}
				for (int i = ans.length - 2; i >= 0; i--) {
					if (ans[i + 1].y > ans[i].y) {
						ans[i].y = ans[i + 1].y;
					}
				}
				for (int i = 0; i < ans.length - 1; i++) {
					max = Math.max(max, ans[i].x + ans[i + 1].y);
				}
				pw.println(max);
//				pw.println(Arrays.toString(ans));
			}
		}
		pw.close();
	}

	static int[] arr;

	static int lower(int s, int x) {
		int start = s, end = arr.length - 1, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				ans = mid;
				start = mid + 1;
			}
		}
		return ans;
	}

	static int upper(int e, int x) {
		int start = 0, end = e, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] < x) {
				start = mid + 1;
			} else {
				ans = mid;
				end = mid - 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int sod(long n) {
		int a = 0;
		while (n > 0) {
			a += n % 10;
			n /= 10;
		}
		return a;
	}

	static PrintWriter pw = new PrintWriter(System.out);

	public static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	public static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class SegmentTree {
		int size;
		int[] st;

		public String toString() {
			return Arrays.toString(st);
		}

		void init(int n) {
			size = 1;
			while (size < n)
				size *= 2;
			st = new int[2 * size];
		}

		void build(int[] arr) {
			build(arr, 0, 0, size);
		}

		void build(int[] arr, int x, int lx, int rx) {
			if (rx - lx == 1) {
				if (lx < arr.length) {
					st[x] = arr[lx];
				}
				return;
			}
			int m = (lx + rx) >> 1;
			build(arr, 2 * x + 1, lx, m);
			build(arr, 2 * x + 2, m, rx);
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		void set(int i, int v) {
			set(i, v, 0, 0, size);
		}

		void set(int i, int v, int x, int l, int r) {
			if (r - l == 1) {
				st[x] = v;
				return;
			}
			int m = (l + r) >> 1;
			if (i < m) {
				set(i, v, 2 * x + 1, l, m);
			} else {
				set(i, v, 2 * x + 2, m, r);
			}
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		long get(int l, int r) {
			return get(l, r + 1, 0, 0, size);
		}

		long get(int l, int r, int x, int lx, int rx) {
			if (lx >= r || rx <= l) {
				return 0;
			} else if (lx >= l && rx <= r) {
				return st[x];
			}
			int m = (lx + rx) >> 1;
			return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
		}

		int find(int idx) {
			return find(idx, 0);
		}

		int find(int idx, int node) {
			if (node >= size - 1) {
				return node - size + 1;
			}
//			pw.print(node + " ");
			if (st[node * 2 + 1] > idx) {
				return find(idx, node * 2 + 1);
			} else {
				return find(idx - st[node * 2 + 1], node * 2 + 2);
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.io.*;

public class cf {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), k = sc.nextInt();
			arr = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}
			Arrays.sort(arr);
			p2[] ans = new p2[n];
			for (int i = 0; i < y.length; i++) {
				ans[i] = new p2(new pair(i - upper(i, arr[i] - k) + 1, i), new pair(lower(i, arr[i] + k) - i + 1, i));
			}
			int max = 0;
			for (int i = 1; i < ans.length; i++) {
				if (ans[i - 1].x.x > ans[i].x.x) {
					ans[i].x = ans[i - 1].x;
				}
			}
			for (int i = ans.length - 2; i >= 0; i--) {
				if (ans[i + 1].y.x > ans[i].y.x) {
					ans[i].y = ans[i + 1].y;
				}
			}
			for (int i = 0; i < ans.length; i++) {
				max = Math.max(max, ans[i].x.x + ans[i].y.x + (ans[i].x.y == ans[i].y.y ? -1 : 0));
			}
			pw.println(max);
//			pw.println(Arrays.toString(ans));
		}
		pw.close();
	}

	public static class p2 {
		pair x, y;

		public String toString() {
			return x + " " + y;
		}

		public p2(pair x, pair y) {
			this.x = x;
			this.y = y;
		}
	}

	static int[] arr;

	static int lower(int s, int x) {
		int start = s, end = arr.length - 1, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				ans = mid;
				start = mid + 1;
			}
		}
		return ans;
	}

	static int upper(int e, int x) {
		int start = 0, end = e, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] < x) {
				start = mid + 1;
			} else {
				ans = mid;
				end = mid - 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int sod(long n) {
		int a = 0;
		while (n > 0) {
			a += n % 10;
			n /= 10;
		}
		return a;
	}

	static PrintWriter pw = new PrintWriter(System.out);

	public static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	public static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class SegmentTree {
		int size;
		int[] st;

		public String toString() {
			return Arrays.toString(st);
		}

		void init(int n) {
			size = 1;
			while (size < n)
				size *= 2;
			st = new int[2 * size];
		}

		void build(int[] arr) {
			build(arr, 0, 0, size);
		}

		void build(int[] arr, int x, int lx, int rx) {
			if (rx - lx == 1) {
				if (lx < arr.length) {
					st[x] = arr[lx];
				}
				return;
			}
			int m = (lx + rx) >> 1;
			build(arr, 2 * x + 1, lx, m);
			build(arr, 2 * x + 2, m, rx);
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		void set(int i, int v) {
			set(i, v, 0, 0, size);
		}

		void set(int i, int v, int x, int l, int r) {
			if (r - l == 1) {
				st[x] = v;
				return;
			}
			int m = (l + r) >> 1;
			if (i < m) {
				set(i, v, 2 * x + 1, l, m);
			} else {
				set(i, v, 2 * x + 2, m, r);
			}
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		long get(int l, int r) {
			return get(l, r + 1, 0, 0, size);
		}

		long get(int l, int r, int x, int lx, int rx) {
			if (lx >= r || rx <= l) {
				return 0;
			} else if (lx >= l && rx <= r) {
				return st[x];
			}
			int m = (lx + rx) >> 1;
			return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
		}

		int find(int idx) {
			return find(idx, 0);
		}

		int find(int idx, int node) {
			if (node >= size - 1) {
				return node - size + 1;
			}
//			pw.print(node + " ");
			if (st[node * 2 + 1] > idx) {
				return find(idx, node * 2 + 1);
			} else {
				return find(idx - st[node * 2 + 1], node * 2 + 2);
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.io.*;

public class cf {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), k = sc.nextInt();
			arr = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}
			Arrays.sort(arr);
			if (n == 1) {
				pw.println(1);
			}
//			else if (2 * k >= arr[n - 1] - arr[0]) {
//				pw.println(n);
//			}
			else {
				p2[] ans = new p2[n];
				for (int i = 0; i < y.length; i++) {
					ans[i] = new p2(new pair(i - upper(i, arr[i] - k) + 1, i),
							new pair(lower(i, arr[i] + k) - i + 1, i));
				}
//				pw.println(Arrays.toString(ans));
				int max = 0;
				for (int i = 1; i < ans.length; i++) {
					if (ans[i - 1].x.x > ans[i].x.x) {
						ans[i].x = ans[i - 1].x;
					}
				}
				for (int i = ans.length - 2; i >= 0; i--) {
					if (ans[i + 1].y.x > ans[i].y.x) {
						ans[i].y = ans[i + 1].y;
					}
				}
				for (int i = 0; i < ans.length - 1; i++) {
					max = Math.max(max, ans[i].x.x + ans[i + 1].y.x);
				}
				pw.println(max);
//				pw.println(Arrays.toString(ans));
			}
		}
		pw.close();
	}

	public static class p2 {
		pair x, y;

		public String toString() {
			return x + " " + y;
		}

		public p2(pair x, pair y) {
			this.x = x;
			this.y = y;
		}
	}

	static int[] arr;

	static int lower(int s, int x) {
		int start = s, end = arr.length - 1, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				ans = mid;
				start = mid + 1;
			}
		}
		return ans;
	}

	static int upper(int e, int x) {
		int start = 0, end = e, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] < x) {
				start = mid + 1;
			} else {
				ans = mid;
				end = mid - 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int sod(long n) {
		int a = 0;
		while (n > 0) {
			a += n % 10;
			n /= 10;
		}
		return a;
	}

	static PrintWriter pw = new PrintWriter(System.out);

	public static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	public static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class SegmentTree {
		int size;
		int[] st;

		public String toString() {
			return Arrays.toString(st);
		}

		void init(int n) {
			size = 1;
			while (size < n)
				size *= 2;
			st = new int[2 * size];
		}

		void build(int[] arr) {
			build(arr, 0, 0, size);
		}

		void build(int[] arr, int x, int lx, int rx) {
			if (rx - lx == 1) {
				if (lx < arr.length) {
					st[x] = arr[lx];
				}
				return;
			}
			int m = (lx + rx) >> 1;
			build(arr, 2 * x + 1, lx, m);
			build(arr, 2 * x + 2, m, rx);
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		void set(int i, int v) {
			set(i, v, 0, 0, size);
		}

		void set(int i, int v, int x, int l, int r) {
			if (r - l == 1) {
				st[x] = v;
				return;
			}
			int m = (l + r) >> 1;
			if (i < m) {
				set(i, v, 2 * x + 1, l, m);
			} else {
				set(i, v, 2 * x + 2, m, r);
			}
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		long get(int l, int r) {
			return get(l, r + 1, 0, 0, size);
		}

		long get(int l, int r, int x, int lx, int rx) {
			if (lx >= r || rx <= l) {
				return 0;
			} else if (lx >= l && rx <= r) {
				return st[x];
			}
			int m = (lx + rx) >> 1;
			return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
		}

		int find(int idx) {
			return find(idx, 0);
		}

		int find(int idx, int node) {
			if (node >= size - 1) {
				return node - size + 1;
			}
//			pw.print(node + " ");
			if (st[node * 2 + 1] > idx) {
				return find(idx, node * 2 + 1);
			} else {
				return find(idx - st[node * 2 + 1], node * 2 + 2);
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.io.*;

public class cf {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), k = sc.nextInt();
			arr = new int[n];
			int[] y = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}
			Arrays.sort(arr);
			if (n == 1) {
				pw.println(1);
			} else if (2 * k >= arr[n - 1] - arr[0]) {
				pw.println(n);
			} else {
				p2[] ans = new p2[n];
				for (int i = 0; i < y.length; i++) {
					ans[i] = new p2(new pair(i - upper(i, arr[i] - k) + 1, i),
							new pair(lower(i, arr[i] + k) - i + 1, i));
				}
//				pw.println(Arrays.toString(ans));
				int max = 0;
				for (int i = 1; i < ans.length; i++) {
					if (ans[i - 1].x.x > ans[i].x.x) {
						ans[i].x = ans[i - 1].x;
					}
				}
				for (int i = ans.length - 2; i >= 0; i--) {
					if (ans[i + 1].y.x > ans[i].y.x) {
						ans[i].y = ans[i + 1].y;
					}
				}
				for (int i = 0; i < ans.length; i++) {
					max = Math.max(max, ans[i].x.x + ans[i].y.x + (ans[i].x.y == ans[i].y.y ? 0 : 0));
				}
				pw.println(max);
//				pw.println(Arrays.toString(ans));
			}
		}
		pw.close();
	}

	public static class p2 {
		pair x, y;

		public String toString() {
			return x + " " + y;
		}

		public p2(pair x, pair y) {
			this.x = x;
			this.y = y;
		}
	}

	static int[] arr;

	static int lower(int s, int x) {
		int start = s, end = arr.length - 1, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				ans = mid;
				start = mid + 1;
			}
		}
		return ans;
	}

	static int upper(int e, int x) {
		int start = 0, end = e, ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] < x) {
				start = mid + 1;
			} else {
				ans = mid;
				end = mid - 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static int sod(long n) {
		int a = 0;
		while (n > 0) {
			a += n % 10;
			n /= 10;
		}
		return a;
	}

	static PrintWriter pw = new PrintWriter(System.out);

	public static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	public static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class SegmentTree {
		int size;
		int[] st;

		public String toString() {
			return Arrays.toString(st);
		}

		void init(int n) {
			size = 1;
			while (size < n)
				size *= 2;
			st = new int[2 * size];
		}

		void build(int[] arr) {
			build(arr, 0, 0, size);
		}

		void build(int[] arr, int x, int lx, int rx) {
			if (rx - lx == 1) {
				if (lx < arr.length) {
					st[x] = arr[lx];
				}
				return;
			}
			int m = (lx + rx) >> 1;
			build(arr, 2 * x + 1, lx, m);
			build(arr, 2 * x + 2, m, rx);
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		void set(int i, int v) {
			set(i, v, 0, 0, size);
		}

		void set(int i, int v, int x, int l, int r) {
			if (r - l == 1) {
				st[x] = v;
				return;
			}
			int m = (l + r) >> 1;
			if (i < m) {
				set(i, v, 2 * x + 1, l, m);
			} else {
				set(i, v, 2 * x + 2, m, r);
			}
			st[x] = st[2 * x + 1] + st[2 * x + 2];
		}

		long get(int l, int r) {
			return get(l, r + 1, 0, 0, size);
		}

		long get(int l, int r, int x, int lx, int rx) {
			if (lx >= r || rx <= l) {
				return 0;
			} else if (lx >= l && rx <= r) {
				return st[x];
			}
			int m = (lx + rx) >> 1;
			return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
		}

		int find(int idx) {
			return find(idx, 0);
		}

		int find(int idx, int node) {
			if (node >= size - 1) {
				return node - size + 1;
			}
//			pw.print(node + " ");
			if (st[node * 2 + 1] > idx) {
				return find(idx, node * 2 + 1);
			} else {
				return find(idx - st[node * 2 + 1], node * 2 + 2);
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            int[] y = new int[n];
            for(int a = 0; a < n; a++)
            {
                y[a] = in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[][] dp = new int[n + 1][2];
                dp[0][0] = 0;
                dp[0][1] = 0;
                int j = 0;
                for(int a = 0; a < n; a++)
                {
                    while(j < n && x[a] + k >= x[j])
                    {
                        j++;
                    }
                    if(a != 0)
                    dp[a][0] = Math.max(dp[a][0], dp[a - 1][0]);
                    if(a != 0)
                    dp[a][1] = Math.max(dp[a][1], dp[a - 1][1]);
                    dp[j][0] = Math.max(dp[j][0], j - a);
                    dp[j][1] = Math.max(dp[j][1], dp[a][0] + j - a);
                }
                int max = 0;
                for(int a = 0; a <= n; a++)
                {
                    for(int b = 0; b < 2; b++)
                    {
                        max = Math.max(dp[a][b], max);
                    }
                }
                out.println(max);
            }
        }
        out.close();
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String args[]) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            int[] y = new int[n];
            for(int a = 0; a < n; a++)
            {
                y[a] = in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[] r = new int[n];
                int[] l = new int[n];
                int j = n - 1;
                for(int a = n - 1; a >= 0; a--)
                {
                    while(x[j] - x[a] > k)
                    {
                        j--;
                    }
                    r[a] = j - a + 1;
                    if(a + 1 < n)
                    {
                        r[a] = Math.max(r[a], r[a + 1]);
                    }
                }
                j = 0;
                for(int a = 0; a < n; a++)
                {
                    while(x[a] - x[j] > k)
                    {
                        j++;
                    }
                    l[a] = a - j + 1;
                    if(a > 0)
                    {
                        l[a] = Math.max(l[a], l[a - 1]);
                    }
                }
                int ans = 0;
                for(int a = 0; a < n - 1; a++)
                {
                    ans = Math.max(ans, l[a] + r[a + 1]);
                }
                out.println(ans);
            }
        }
        out.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String args[]) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            int[] y = new int[n];
            for(int a = 0; a < n; a++)
            {
                y[a] = in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[][] dp = new int[n + 1][2];
                dp[0][0] = 0;
                dp[0][1] = 0;
                int j = 0;
                for(int a = 0; a < n; a++)
                {
                    while(j < n && x[a] + k >= x[j])
                    {
                        j++;
                    }
                    if(a != 0)
                    dp[a][0] = Math.max(dp[a][0], dp[a - 1][0]);
                    if(a != 0)
                    dp[a][1] = Math.max(dp[a][1], dp[a - 1][1]);
                    dp[j][0] = Math.max(dp[j][0], j - a);
                    dp[j][1] = Math.max(dp[j][1], dp[a][0] + j - a);
                }
                out.println(dp[n][1]);
            }
        }
        out.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            for(int a = 0; a < n; a++)
            {
                in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[] arr = new int[n];
                int count = 0;
                for(int a = 0; a < n; a++)
                {
                    while(x[a] - k > x[count])
                    {
                        count++;
                    }
                    arr[a] = count;
                }
                int ans = 0;
                int[][] dp = new int[n][2];
                for(int a = 0; a < n; a++) {
                    dp[a][1] = dp[a][0] = a - arr[a] + 1;
                    if(a > 0)dp[a][0] = Math.max(dp[a][0], dp[a - 1][0]);
                    if (arr[a] > 0)
                    {
                        dp[a][1] += dp[arr[a] - 1][0];
                    }
                    ans = Math.max(dp[a][1], ans);
                }
                out.println(ans);
            }
        }
        out.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for (int a = 0; a < n; a++) {
                x[a] = in.nextInt();
            }
            for (int a = 0; a < n; a++) {
                in.nextInt();
            }
            shuffleArray(x);
            Arrays.sort(x);
            int[] arr = new int[n];
            int count = 0;
            for (int a = 0; a < n; a++) {
                while (x[a] - k > x[count]) {
                    count++;
                }
                arr[a] = count;
            }
            int ans = 0;
            int[][] dp = new int[n][2];
            for (int a = 0; a < n; a++) {
                dp[a][1] = dp[a][0] = a - arr[a] + 1;
                if (a > 0) dp[a][0] = Math.max(dp[a][0], dp[a - 1][0]);
                if (arr[a] > 0) {
                    dp[a][1] += dp[arr[a] - 1][0];
                }
                ans = Math.max(dp[a][1], ans);
            }
            out.println(ans);
        }
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    // template code
    public static void shuffleArray(int[] arr) {
        int n = arr.length;
        Random rnd = new Random();
        for (int i = 0; i < n; ++i) {
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n - i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for (int a = 0; a < n; a++) {
                x[a] = in.nextInt();
            }
            for (int a = 0; a < n; a++) {
                in.nextInt();
            }
            Arrays.sort(x);
            int[] arr = new int[n];
            int count = 0;
            for (int a = 0; a < n; a++) {
                while (x[a] - k > x[count]) {
                    count++;
                }
                arr[a] = count;
            }
            int ans = 0;
            int[][] dp = new int[n][2];
            for (int a = 0; a < n; a++) {
                dp[a][1] = dp[a][0] = a - arr[a] + 1;
                if (a > 0) dp[a][0] = Math.max(dp[a][0], dp[a - 1][0]);
                if (arr[a] > 0) {
                    dp[a][1] += dp[arr[a] - 1][0];
                }
                ans = Math.max(dp[a][1], ans);
            }
            out.println(ans);
        }
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            int[] y = new int[n];
            for(int a = 0; a < n; a++)
            {
                y[a] = in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[] r = new int[n];
                int[] l = new int[n];
                int j = n - 1;
                for(int a = n - 1; a >= 0; a--)
                {
                    while(x[j] - x[a] > k)
                    {
                        j--;
                    }
                    r[a] = j - a + 1;
                    if(a + 1 < n)
                    {
                        r[a] = Math.max(r[a], r[a + 1]);
                    }
                }
                j = 0;
                for(int a = 0; a < n; a++)
                {
                    while(x[a] - x[j] > k)
                    {
                        j++;
                    }
                    l[a] = a - j + 1;
                    if(a > 0)
                    {
                        l[a] = Math.max(l[a], l[a - 1]);
                    }
                }
                int ans = 0;
                for(int a = 0; a < n - 1; a++)
                {
                    ans = Math.max(ans, l[a] + r[a + 1]);
                }
                out.println(ans);
            }
        }
        out.close();
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String args[]) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            int[] y = new int[n];
            for(int a = 0; a < n; a++)
            {
                y[a] = in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[][] dp = new int[n + 1][2];
                dp[0][0] = 0;
                dp[0][1] = 0;
                int j = 0;
                for(int a = 0; a < n; a++)
                {
                    while(j < n && x[a] + k >= x[j])
                    {
                        j++;
                    }
                    if(a != 0)
                    dp[a][0] = Math.max(dp[a][0], dp[a - 1][0]);
                    if(a != 0)
                    dp[a][1] = Math.max(dp[a][1], dp[a - 1][1]);
                    dp[j][0] = Math.max(dp[j][0], j - a);
                    dp[j][1] = Math.max(dp[j][1], dp[a][0] + j - a);
                }
                int max = 0;
                for(int a = 0; a <= n; a++)
                {
                    for(int b = 0; b < 2; b++)
                    {
                        max = Math.max(dp[a][b], max);
                    }
                }
                out.println(max);
            }
        }
        out.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        for(int i = 0; i < t; i++)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = new int[n];
            for(int a = 0; a < n; a++)
            {
                x[a] = in.nextInt();
            }
            for(int a = 0; a < n; a++)
            {
                in.nextInt();
            }
            if(n == 1)
            {
                out.println(1);
            }
            else
            {
                Arrays.sort(x);
                int[] arr = new int[n];
                int count = 0;
                for(int a = 0; a < n; a++)
                {
                    while(x[a] - k > x[count])
                    {
                        count++;
                    }
                    arr[a] = count;
                }
                int ans = 0;
                int[][] dp = new int[n][2];
                for(int a = 0; a < n; a++) {
                    dp[a][1] = dp[a][0] = a - arr[a] + 1;
                    if(a > 0)dp[a][0] = Math.max(dp[a][0], dp[a - 1][1]);
                    if (arr[a] > 0)
                    {
                        dp[a][1] += dp[arr[a] - 1][0];
                    }
                    ans = Math.max(dp[a][1], ans);
                }
                out.println(ans);
            }
        }
        out.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void solve(Scanner in, PrintWriter out) {
        int t = in.nextInt();
        for (int i = 0; i < t; ++i) {
            int n = in.nextInt();
            long k = in.nextLong();
            Long xx[] = new Long[n];

            for (int j = 0; j < n; ++j) {
                xx[j] = in.nextLong();
            }

            for (int j = 0; j < n; ++j) {
                in.nextLong();
            }
            Arrays.sort(xx);

            long[] ll = new long[n];
            long[] rr = new long[n];
            int k1 = 0;
            long res = 1;

            for (int k2 = 0; k2 < n; ++k2) {
                while (xx[k2] - xx[k1] > k)
                    ++k1;
                ll[k2] = k2 - k1 + 1;
                if (k2 > 0)
                    ll[k2] = Math.max(ll[k2], ll[k2 - 1]);
            }

            k1 = n - 1;
            for (int k2 = n - 1; k2 >= 0; --k2) {
                while (xx[k1] - xx[k2] > k)
                    --k1;
                rr[k2] = k1 - k2 + 1;
                if (k2 < n - 1)
                    rr[k2] = Math.max(rr[k2], rr[k2 + 1]);
            }

            for (int m = 0; m < n - 1; ++m) {
                res = Math.max(res, rr[m + 1] + ll[m]);
            }
            out.println(res);
        }
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void solve(Scanner in, PrintWriter out) {
        int t = in.nextInt();
        for (int i = 0; i < t; ++i) {
            int n = in.nextInt();
            long k = in.nextLong();
            long xx[] = new long[n];

            for (int j = 0; j < n; ++j) {
                xx[j] = in.nextLong();
            }

            for (int j = 0; j < n; ++j) {
                in.nextLong();
            }
            Arrays.sort(xx);

            long[] ll = new long[n];
            long[] rr = new long[n];
            int k1 = 0;
            long res = 1;

            for (int k2 = 0; k2 < n; ++k2) {
                while (xx[k2] - xx[k1] > k)
                    ++k1;
                ll[k2] = k2 - k1 + 1;
                if (k2 > 0)
                    ll[k2] = Math.max(ll[k2], ll[k2 - 1]);
            }

            k1 = n - 1;
            for (int k2 = n - 1; k2 >= 0; --k2) {
                while (xx[k1] - xx[k2] > k)
                    --k1;
                rr[k2] = k1 - k2 + 1;
                if (k2 < n - 1)
                    rr[k2] = Math.max(rr[k2], rr[k2 + 1]);
            }

            for (int m = 0; m < n - 1; ++m) {
                res = Math.max(res, rr[m + 1] + ll[m]);
            }
            out.println(res);
        }
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
// Please name your class Main
public class Main {

	static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static int read() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static String readString() throws IOException {
        in.nextToken();
        return in.sval;
	}

	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//InputReader in = new InputReader(System.in);

		int T=in.nextInt();
		for(int i=0;i<T;i++){
			int n=in.nextInt();
			long k=in.nextLong();
			long x[]=new long[n];
			long y[]=new long[n];
			for(int j=0;j<n;j++){
				x[j]=in.nextLong();
			}

			for(int j=0;j<n;j++){
				y[j]=in.nextLong();
			}
			Solution sol=new Solution();
			sol.solution(x,y,k);
		}

		out.flush();

		}

}

class Solution{
	//constant variable
	final int MAX=Integer.MAX_VALUE;
	final int MIN=Integer.MIN_VALUE;
	//Set<Integer>adjecent[];
	//////////////////////////////

	public void solution(long A[],long B[],long k){
		long res=0;
		Map<Long,Integer>map=new HashMap<>();
		for(int i=0;i<A.length;i++){
			long x=A[i];
			long y=B[i];
			if(!map.containsKey(x))map.put(x,0);
			map.put(x,map.get(x)+1);
		}

		//System.out.println(map);

		List<long[]>list=new ArrayList<>();
		for(Long key:map.keySet()){
			list.add(new long[]{key,map.get(key)});
		}
		Collections.sort(list,(a,b)->{
			return Long.compare(a[0],b[0]);
		});

		//System.out.println(list.size());

		/*long pre[]=new long[list.size()];
		long sum=0;
		for(int i=0;i<list.size();i++){
			sum+=list.get(i)[1];
			pre[i]=sum;
		}*/

		long sum=0;
		long pre[]=new long[list.size()];
		long post[]=new long[list.size()];

		Queue<long[]>q=new LinkedList<>();
		for(int i=0;i<list.size();i++){
			long x=list.get(i)[0];
			long cnt=list.get(i)[1];

			while(q.size()>0&&x-q.peek()[0]>k){
				long top[]=q.poll();
				sum-=top[1];
			}

			sum+=cnt;
			q.add(new long[]{x,cnt});
			pre[i]=Math.max(get(pre,i-1),sum);
		}

		q=new LinkedList<>();
		sum=0;

		for(int i=list.size()-1;i>=0;i--){
			long x=list.get(i)[0];
			long cnt=list.get(i)[1];

			while(q.size()>0&&Math.abs(x-q.peek()[0])>k){
				long top[]=q.poll();
				sum-=top[1];
			}

			sum+=cnt;
			q.add(new long[]{x,cnt});
			post[i]=Math.max(get(post,i+1),sum);
		}

		//get the result
		for(int i=0;i<pre.length;i++){
			res=Math.max(res,pre[i]+get(post,i+1));
		}
		msg(res+"");

	}

   public long get(long A[],int i){
	   if(i<0||i>=A.length)return 0;
	   return A[i];
   }

	/*public void tarjan(int p,int r){
		if(cut)return;
		List<Integer>childs=adjecent[r];
		dis[r]=low[r]=time;
		time++;

		//core for tarjan
		int son=0;
		for(int c:childs){
			if(ban==c||c==p)continue;
			if(dis[c]==-1){
				son++;
				tarjan(r,c);
				low[r]=Math.min(low[r],low[c]);
				if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
					cut=true;
					return;
				}
			}else{
				if(c!=p){
					low[r]=Math.min(low[r],dis[c]);
				}
			}
		}

	}*/

	//helper function I would use
	public void ascii(String s){
		for(char c:s.toCharArray()){
			System.out.print((c-'a')+" ");
		}
		msg("");
	}

	public int flip(int i){
		if(i==0)return 1;
		else return 0;
	}

	public boolean[] primes(int n){
		boolean A[]=new boolean[n+1];
		for(int i=2;i<=n;i++){
			if(A[i]==false){
				for(int j=i+i;j<=n;j+=i){
					A[j]=true;
				}
			}
		}
		return A;
	}

	public void msg(String s){
		System.out.println(s);
	}

	public int[] kmpPre(String p){
		int pre[]=new int[p.length()];
		int l=0,r=1;
		while(r<p.length()){
			if(p.charAt(l)==p.charAt(r)){
				pre[r]=l+1;
				l++;r++;
			}else{
				if(l==0)r++;
				else l=pre[l-1];
			}
		}
		return pre;
	}

	public boolean isP(String s){
		int l=0,r=s.length()-1;
		while(l<r){
			if(s.charAt(l)!=s.charAt(r))return false;
			l++;r--;
		}
		return true;
	}

	public int find(int nums[],int x){//union find => find method
		if(nums[x]==x)return x;
		int root=find(nums,nums[x]);
		nums[x]=root;
		return root;
	}

	public boolean check(int grid[][],int r,int c){
		if(r<0||c<0||r>=grid.length||c>=grid[0].length)return false;
		return true;
	}

	public int get(int A[],int i){
		if(i<0||i>=A.length)return 0;
		return A[i];
	}
	public int[] copy1(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public int[] copy2(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public void print1(int A[]){
		for(long i:A)System.out.print(i+" ");
		System.out.println();
	}
	public void print2(int A[][]){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}System.out.println();
		}
	}

	public int min(int a,int b){
		return Math.min(a,b);
	}

	public int[][] matrixdp(int[][] grid) {
        if(grid.length==0)return new int[][]{};
        int res[][]=new int[grid.length][grid[0].length];
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
            }
        }
        return res;
    }

    public int get(int grid[][],int i,int j){
        if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
        return grid[i][j];
    }

	public int[] suffixArray(String s){
		int n=s.length();
		Suffix A[]=new Suffix[n];

		for(int i=0;i<n;i++){
			A[i]=new Suffix(i,s.charAt(i)-'a',0);
		}

		for(int i=0;i<n;i++){
			if(i==n-1){
				A[i].next=-1;
			}else{
				A[i].next=A[i+1].rank;
			}
		}
		Arrays.sort(A);

		for(int len=4;len<A.length*2;len<<=1){
			int in[]=new int[A.length];
			int rank=0;
			int pre=A[0].rank;
			A[0].rank=rank;
			in[A[0].index]=0;
			for(int i=1;i<A.length;i++){//rank for the first two letter
				if(A[i].rank==pre&&A[i].next==A[i-1].next){
					pre=A[i].rank;
					A[i].rank=rank;
				}else{
					pre=A[i].rank;
					A[i].rank=++rank;
				}
				in[A[i].index]=i;
			}

			for(int i=0;i<A.length;i++){
				int next=A[i].index+len/2;
				if(next>=A.length){
					A[i].next=-1;
				}else{
					A[i].next=A[in[next]].rank;
				}
			}

			Arrays.sort(A);
		}

		int su[]=new int[A.length];
		for(int i=0;i<su.length;i++){
			su[i]=A[i].index;
		}
		return su;
	}

}

//suffix array Struct
class Suffix implements Comparable<Suffix>{
	int index;
	int rank;
	int next;
	public Suffix(int i,int rank,int next){
		this.index=i;
		this.rank=rank;
		this.next=next;
	}

	@Override
	public int compareTo(Suffix other) {
		if(this.rank==other.rank){
			return this.next-other.next;
		}
		return this.rank-other.rank;
	}

	public String toString(){
		return this.index+"   "+this.rank+"   "+this.next+"  ";
	}
}

class Wrapper implements Comparable<Wrapper>{
	int spf;int cnt;
	public Wrapper(int spf,int cnt){
		this.spf=spf;
		this.cnt=cnt;
	}

	@Override
	public int compareTo(Wrapper other) {
		return this.spf-other.spf;
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader reader = new FastReader();
        BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
        try {
            int t = reader.nextInt();
            for (int i = 0; i < t; i++) {
                int n = reader.nextInt();
                int k = reader.nextInt();

                int x[] = new int[n];

                for (int j = 0; j < n; j++) {
                    x[j] = reader.nextInt();
                }
                for (int j = 0; j < n; j++) {
                    reader.nextInt();
                }

                sort(x, 0, n - 1);

                int maxFromHere[] = new int[n];
                int max[] = new int[n];
                int idx[] = new int[n];

                for (int j = 0; j < n - 1; j++) {
                    int index = closestSmaller(x, x[j] + k, j);
                    idx[j] = index + 1;
                    maxFromHere[j] = (index - j + 1);
                }
                maxFromHere[n - 1] = 1;
                idx[n - 1] = n;

                max[n - 1] = maxFromHere[n - 1];
                for (int j = n - 2; j >= 0; j--) {
                    max[j] = Math.max(max[j + 1], maxFromHere[j]);
                }

                int ans = 0;
                for (int j = 0; j < n; j++) {
                    if (idx[j] < n) {
                        ans = Math.max(ans, maxFromHere[j] + max[idx[j]]);
                    } else {
                        ans = Math.max(ans, maxFromHere[j]);
                    }
                }

                log.write(ans + "\n");
                log.flush();
            }
            log.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static int closestSmaller(int[] x, int val, int j) {
        int n = x.length;
        int low = j, high = n - 1;

        while (low <= high) {
            int mid = (low + high) / 2;
            if (x[mid] > val) {
                high = mid - 1;
            } else {
                if (mid == n - 1 || x[mid + 1] > val) {
                    return mid;
                } else {
                    low = mid + 1;
                }
            }
        }

        return -1;
    }

    private static void merge(int arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    private static void sort(int arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader reader = new FastReader();
        BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
        try {
            int t = reader.nextInt();
            for (int i = 0; i < t; i++) {
                int n = reader.nextInt();
                int k = reader.nextInt();

                int x[] = new int[n];

                for (int j = 0; j < n; j++) {
                    x[j] = reader.nextInt();
                }
                for (int j = 0; j < n; j++) {
                    reader.nextInt();
                }

                Arrays.sort(x);

                int maxFromHere[] = new int[n];
                int max[] = new int[n];
                int idx[] = new int[n];

                for (int j = 0; j < n - 1; j++) {
                    int index = closestSmaller(x, x[j] + k);
                    idx[j] = index + 1;
                    maxFromHere[j] = (index - j + 1);
                }
                maxFromHere[n - 1] = 1;
                idx[n - 1] = n;

                max[n - 1] = maxFromHere[n - 1];
                for (int j = n - 2; j >= 0; j--) {
                    max[j] = Math.max(max[j + 1], maxFromHere[j]);
                }

                int ans = 0;
                for (int j = 0; j < n; j++) {
                    if (idx[j] < n) {
                        ans = Math.max(ans, maxFromHere[j] + max[idx[j]]);
                    } else {
                        ans = Math.max(ans, maxFromHere[j]);
                    }
                }

                log.write(ans + "\n");
                log.flush();
            }
            log.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static int closestSmaller(int[] x, int val) {
        int n = x.length;
        int low = 0, high = n - 1;

        while (low <= high) {
            int mid = (low + high) / 2;
            if (x[mid] > val) {
                high = mid - 1;
            } else {
                if (mid == n - 1 || x[mid + 1] > val) {
                    return mid;
                } else {
                    low = mid + 1;
                }
            }
        }
        return -1;
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class TwoPlatforms {
    public static void main(String[] args) {
        FastReader reader = new FastReader();
        BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
        try {
            int t = reader.nextInt();
            for (int i = 0; i < t; i++) {
                int n = reader.nextInt();
                int k = reader.nextInt();

                int x[] = new int[n];

                for (int j = 0; j < n; j++) {
                    x[j] = reader.nextInt();
                }
                for (int j = 0; j < n; j++) {
                    reader.nextInt();
                }

                Arrays.sort(x);

                int maxFromHere[] = new int[n];
                int max[] = new int[n];
                int idx[] = new int[n];

                for (int j = 0; j < n - 1; j++) {
                    int index = closestSmaller(x, x[j] + k, j);
                    idx[j] = index + 1;
                    maxFromHere[j] = (index - j + 1);
                }
                maxFromHere[n - 1] = 1;
                idx[n - 1] = n;

                max[n - 1] = maxFromHere[n - 1];
                for (int j = n - 2; j >= 0; j--) {
                    max[j] = Math.max(max[j + 1], maxFromHere[j]);
                }

                int ans = 0;
                for (int j = 0; j < n; j++) {
                    if (idx[j] < n) {
                        ans = Math.max(ans, maxFromHere[j] + max[idx[j]]);
                    } else {
                        ans = Math.max(ans, maxFromHere[j]);
                    }
                }

                log.write(ans + "\n");
                log.flush();
            }
            log.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static int closestSmaller(int[] x, int val, int j) {
        int n = x.length;
        int low = j, high = n - 1;

        while (low <= high) {
            int mid = (low + high) / 2;
            if (x[mid] > val) {
                high = mid - 1;
            } else {
                if (mid == n - 1 || x[mid + 1] > val) {
                    return mid;
                } else {
                    low = mid + 1;
                }
            }
        }

        return -1;
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.io.*;

public class Two_Platforms {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int test = t.nextInt();

		while (test-- > 0) {
			int n = t.nextInt();
			long k = t.nextLong();
			long[] x = new long[n];
			long[] y = new long[n];

			for (int i = 0; i < n; ++i)
				x[i] = t.nextLong();

			for (int i = 0; i < n; ++i)
				y[i] = t.nextLong();

			o.println(okgoogle(x, n, k));
		}

		o.flush();
		o.close();
	}

	private static int okgoogle(long[] x, int n, long k) {
		int ans = 0;

		if (n == 1)
			return 1;

		int[] left = new int[n];
		int[] right = new int[n];

		int i = 0, j = 0;

		while (j < n) {
			if (x[j] - x[i] <= k) {
				if (j > 0) {
					left[j] = Math.max(j - i + 1, left[j - 1]);
				} else {
					left[j] = j - i + 1;
				}

				++j;
			} else {
				++i;
			}
		}

		i = j = n - 1;

		while (i >= 0) {
			if (x[j] - x[i] <= k) {
				if (i != n - 1) {
					right[i] = Math.max(right[i + 1], j - i + 1);
				} else {
					right[i] = j - i + 1;
				}

				--i;
			} else
				--j;
		}

		for (i = 0; i < n - 1; ++i)
			ans = Math.max(ans, right[i + 1] + left[i]);

		return ans;
	}
}


import java.util.*;
import java.io.*;

public class Two_Platforms {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int test = t.nextInt();

		while (test-- > 0) {
			int n = t.nextInt();
			long k = t.nextLong();
			long[] x = new long[n];
			long[] y = new long[n];

			for (int i = 0; i < n; ++i)
				x[i] = t.nextLong();

			for (int i = 0; i < n; ++i)
				y[i] = t.nextLong();

			Arrays.sort(x);

			o.println(okgoogle(x, n, k));
		}

		o.flush();
		o.close();
	}

	private static int okgoogle(long[] x, int n, long k) {
		int ans = 0;

		if (n == 1)
			return 1;

		int[] left = new int[n];
		int[] right = new int[n];

		int i = 0, j = 0;

		while (j < n) {
			if (x[j] - x[i] <= k) {
				if (j > 0) {
					left[j] = Math.max(Math.max(left[j], j - i + 1), left[j - 1]);
				} else {
					left[j] = j - i + 1;
				}

				++j;
			} else {
				++i;
			}
		}

		i = j = n - 1;

		while (i >= 0) {
			if (x[j] - x[i] <= k) {
				if (i != n - 1) {
					right[i] = Math.max(right[i + 1], Math.max(right[i], j - i + 1));
				} else {
					right[i] = j - i + 1;
				}

				--i;
			} else
				--j;
		}

		for (i = 0; i < n - 1; ++i)
			ans = Math.max(ans, right[i + 1] + left[i]);

		return ans;
	}
}


import java.util.*;
import java.io.*;

public class Two_Platforms {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int test = t.nextInt();

		while (test-- > 0) {
			int n = t.nextInt();
			long k = t.nextLong();
			Long[] x = new Long[n];
			long[] y = new long[n];

			for (int i = 0; i < n; ++i)
				x[i] = t.nextLong();

			for (int i = 0; i < n; ++i)
				y[i] = t.nextLong();

			Arrays.sort(x);

			o.println(okgoogle(x, n, k));
		}

		o.flush();
		o.close();
	}

	private static int okgoogle(Long[] x, int n, long k) {
		int ans = 0;

		if (n == 1)
			return 1;

		int[] left = new int[n];
		int[] right = new int[n];

		int i = 0, j = 0;

		while (j < n) {
			if (x[j].longValue() - x[i].longValue() <= k) {
				if (j > 0) {
					left[j] = Math.max(Math.max(left[j], j - i + 1), left[j - 1]);
				} else {
					left[j] = j - i + 1;
				}

				++j;
			} else {
				++i;
			}
		}

		i = j = n - 1;

		while (i >= 0) {
			if (x[j].longValue() - x[i].longValue() <= k) {
				if (i != n - 1) {
					right[i] = Math.max(right[i + 1], Math.max(right[i], j - i + 1));
				} else {
					right[i] = j - i + 1;
				}

				--i;
			} else
				--j;
		}

		for (i = 0; i < n - 1; ++i)
			ans = Math.max(ans, right[i + 1] + left[i]);

		return ans;
	}
}


import java.util.*;
import java.io.*;

public class Two_Platforms {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int test = t.nextInt();

		while (test-- > 0) {
			int n = t.nextInt();
			long k = t.nextLong();
			long[] x = new long[n];
			long[] y = new long[n];

			for (int i = 0; i < n; ++i)
				x[i] = t.nextLong();

			for (int i = 0; i < n; ++i)
				y[i] = t.nextLong();

			Arrays.sort(x);

			o.println(okgoogle(x, n, k));
		}

		o.flush();
		o.close();
	}

	private static int okgoogle(long[] x, int n, long k) {
		int ans = 0;

		if (n == 1)
			return 1;

		int[] left = new int[n];
		int[] right = new int[n];

		int i = 0, j = 0;

		while (j < n) {
			if (x[j] - x[i] <= k) {
				if (j > 0) {
					left[j] = Math.max(j - i + 1, left[j - 1]);
				} else {
					left[j] = j - i + 1;
				}

				++j;
			} else {
				++i;
			}
		}

		i = j = n - 1;

		while (i >= 0) {
			if (x[j] - x[i] <= k) {
				if (i != n - 1) {
					right[i] = Math.max(right[i + 1], j - i + 1);
				} else {
					right[i] = j - i + 1;
				}

				--i;
			} else
				--j;
		}

		for (i = 0; i < n - 1; ++i)
			ans = Math.max(ans, right[i + 1] + left[i]);

		return ans;
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class Q5 {
	static long[] segtree;
	static int[] dp;
	public static void main(String[] args) {
		/*
		 * */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int T = I.nextInt();
		while (T-->0) {
			int N = I.nextInt();
			long K = I.nextLong();
			long ans=0;
			ArrayList<Long> x = new ArrayList<Long>(); //Only x coordinates matter since
			//y can be fixed for some negative value (below all points vertically)
			ArrayList<Long> y = new ArrayList<Long>();
			dp = new int[N];
			//Maximum suffix is fine
			long[] suff = new long[N];
			for (int i = 0; i < N; i++) {
				x.add(I.nextLong());
			}
			for (int i = 0; i < N; i++) y.add(I.nextLong());
			Collections.sort(x);
			Collections.sort(y);
			for (int L = 0; L<N; L++) {
				long curx = x.get(L);
				int lo = L; int hi = N-1;
				int R = L;
				while (lo<=hi) {
					int mid = (lo+hi)/2;
					long test = x.get(mid);
					if (test<=curx+K) {
						lo=mid+1;
						R=max(R,mid);
					}else hi=mid-1;
				}
				dp[L]=R-L+1; //Maximum extension of segment starting at current x-coordinate
			}
			suff[N-1]=dp[N-1];
			for (int i = N-2; i >= 0; i--) {
				suff[i]=max(suff[i+1],dp[i]);
			}
			for (int i = 0; i < N; i++) {
				int curans = dp[i];
				int after = i+curans; //Earliest point we can assess
				if (after<N) curans+=suff[after];
				ans=max(ans,curans);
			}
			O.pln(ans);
		}
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0)
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


import java.io.*;
import java.util.*;

public class gym{
	static void main() throws Exception{
		int n=sc.nextInt(),k=sc.nextInt();
		int[]in=sc.intSortedArr(n);
		sc.intArr(n);
		int ans=0;
		int[]best=new int[n];
		for(int i=n-1;i>=0;i--) {
			int lo=i+1,hi=n-1;
			int last=i;
			while(lo<=hi) {
				int mid=(lo+hi)>>1;
				if(in[mid]-in[i]<=k) {
					last=mid;
					lo=mid+1;
				}
				else {
					hi=mid-1;
				}
			}
			int cur=last-i+1;
			//the best for current suffix using one segment
			best[i]=Math.max(i==n-1?0:best[i+1], cur);
			if(last<n-1) {
				cur+=best[last+1];
			}
			ans=Math.max(ans, cur);

		}
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*(i+1));
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*(i+1));
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}