There are N problems numbered 1..N which you need to complete. You've arranged the problems in increasing difficulty order, and the i^{th} problem has estimated difficulty level i. You have also assigned a rating vi to each problem. Problems with similar vi values are similar in nature. On each day, you will choose a subset of the problems and solve them. You've decided that each subsequent problem solved on the day should be tougher than the previous problem you solved on that day. Also, to make it less boring, consecutive problems you solve should differ in their vi rating by at least K. What is the least number of days in which you can solve all problems?

Input Format

The first line contains the number of test cases T. T test cases follow. Each case contains an integer N and K on the first line, followed by integers v1,...,vn on the second line.

Constraints

1 <= T <= 100 

1 <= N <= 300 

1 <= vi <= 1000 

1 <= K <= 1000

Output Format

Output T lines, one for each test case, containing the minimum number of days in which all problems can be solved.

Sample Input
2  
3 2  
5 4 7  
5 1  
5 3 4 5 6

Sample Output
2  
1

Explanation

For the first example, you can solve the problems with rating 5 and 7 on the first day and the problem with rating 4 on the next day. Note that the problems with rating 5 and 4 cannot be completed consecutively because the ratings should differ by at least K (which is 2). Also, the problems cannot be completed in order 5,7,4 in one day because the problems solved on a day should be in increasing difficulty level.

For the second example, all problems can be solved on the same day.

Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Starter code:

Solutions:
G = []
V = []
M = []

def find(v):
	for u in G[v]:
		if not V[u]:
			V[u] = True
			if M[u] == -1 or find(M[u]):
				M[u] = v
				return True
	return False
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	G = [[] for _ in range(n)]
	V = [False for _ in range(n)]
	M = [-1 for _ in range(n)]
	vi = list(map(int, input().split()))
	for x in range(n):
		for y in range(x + 1, n):
			if abs(vi[x] - vi[y]) >= k:
				G[x].append(y)
	res = 0
	for i in range(n):
		V = [False for _ in range(n)]
		if find(i):
			res += 1
	print(n - res)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	vi = list(map(int, input().split()))
	m = [None] * N

	def match(s):
		if v[s]:
			return False
		v[s] = True
		for i in range(s + 1, N):
			if abs(vi[i] - vi[s]) < K:
				continue
			if m[i] == None or match(m[i]):
				m[i] = s
				return True
		return False
	mc = 0
	for i in range(N):
		v = [False] * N
		if match(i):
			mc += 1
	print(N - mc)


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B, R) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N, N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(R - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys
G = []
V = []
M = []

def find(v):
	for u in G[v]:
		if not V[u]:
			V[u] = True
			if M[u] == -1 or find(M[u]):
				M[u] = v
				return True
	return False
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	G = [[] for _ in range(n)]
	V = [False for _ in range(n)]
	M = [-1 for _ in range(n)]
	vi = list(map(int, input().split()))
	for x in range(n):
		for y in range(x + 1, n):
			if abs(vi[x] - vi[y]) >= k:
				G[x].append(y)
	res = 0
	for i in range(n):
		V = [False for _ in range(n)]
		if find(i):
			res += 1
	print(n - res)


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	vi = list(map(int, input().split()))
	m = [None] * N

	def match(s):
		if v[s]:
			return False
		v[s] = True
		for i in range(s + 1, N):
			if abs(vi[i] - vi[s]) < K:
				continue
			if m[i] == None or match(m[i]):
				m[i] = s
				return True
		return False
	mc = 0
	for i in range(N):
		v = [False] * N
		if match(i):
			mc += 1
	print(N - mc)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	vi = list(map(int, input().split()))
	m = [None] * N

	def match(s):
		if v[s]:
			return False
		v[s] = True
		for i in range(s + 1, N):
			if abs(vi[i] - vi[s]) < K:
				continue
			if m[i] == None or match(m[i]):
				m[i] = s
				return True
		return False
	mc = 0
	for i in range(N):
		v = [False] * N
		if match(i):
			mc += 1
	print(N - mc)


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def aug(u, G, M, seen):
	for v in G[u]:
		if not seen[v]:
			seen[v] = True
			if M[v] == None or aug(M[v], G, M, seen):
				M[v] = u
				return True
	return False

def bip_match(G, Us, Vs):
	M = [None] * Vs
	for u in range(Us):
		aug(u, G, M, [False] * Vs)
	return M

def main():
	T = int(input())
	for _ in range(T):
		(N, K) = map(int, input().split())
		V = list(map(int, input().split()))
		Order = [[] for _ in range(N)]
		for u in range(N):
			for v in range(u + 1, N):
				if abs(V[u] - V[v]) >= K:
					Order[u].append(v)
		M = bip_match(Order, N, N)
		Ms = sum((1 for u in M if u is None))
		print(Ms)
main()


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def problemSolving(k, v):
	fptr = open(os.environ['OUTPUT_PATH'], 'w')
	t = int(input())
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	v = list(map(int, input().rstrip().split()))
	result = problemSolving(k, v)
	fptr.write(str(result) + '\n')
	fptr.close()

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def problemSolving(k, v):
	fptr = open(os.environ['OUTPUT_PATH'], 'w')
	t = int(input())
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	v = list(map(int, input().rstrip().split()))
	result = problemSolving(k, v)
	fptr.write(str(result) + '\n')
	fptr.close()

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	vi = list(map(int, input().split()))
	m = [None] * n

	def match(s):
		if v[s]:
			return False
		v[s] = True
		for i in range(s + 1, n):
			if abs(vi[i] - vi[s]) < k:
				continue
			if m[i] == None or match(m[i]):
				m[i] = s
				return True
		return False
	mc = 0
	for i in range(n):
		v = [False] * n
		if match(i):
			mc += 1
	print(n - mc)


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def ansFun(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or ansFun(B[x], s):
				B[x] = i
				return 1
	return 0
for sejalMadarchot in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: ansFun(i, i), range(N))))


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	vi = list(map(int, input().split()))
	m = [None] * N

	def match(s):
		if v[s]:
			return False
		v[s] = True
		for i in range(s + 1, N):
			if abs(vi[i] - vi[s]) < K:
				continue
			if m[i] == None or match(m[i]):
				m[i] = s
				return True
		return False
	mc = 0
	for i in range(N):
		v = [False] * N
		if match(i):
			mc += 1
	print(N - mc)


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input())):
	val = list(map(int, input().strip().split()))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * val[0], [-1] * val[0])
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= val[1], range(i + 1, val[0]))) for i in range(val[0])]
	print(val[0] - sum(map(lambda i: hung(i, i), range(val[0]))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys
G = []
V = []
M = []

def find(v):
	for u in G[v]:
		if not V[u]:
			V[u] = True
			if M[u] == -1 or find(M[u]):
				M[u] = v
				return True
	return False
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	G = [[] for _ in range(n)]
	V = [False for _ in range(n)]
	M = [-1 for _ in range(n)]
	vi = list(map(int, input().split()))
	for x in range(n):
		for y in range(x + 1, n):
			if abs(vi[x] - vi[y]) >= k:
				G[x].append(y)
	res = 0
	for i in range(n):
		V = [False for _ in range(n)]
		if find(i):
			res += 1
	print(n - res)


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


import os
import sys

def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))


def hung(i, s):
	for x in E[i]:
		if F[x] != s:
			F[x] = s
			if B[x] == -1 or hung(B[x], s):
				B[x] = i
				return 1
	return 0
for _ in range(int(input().strip())):
	(N, K) = map(int, input().strip().split(' '))
	(D, F, B) = ([int(x) for x in input().strip().split()], [-1] * N, [-1] * N)
	E = [list(filter(lambda j: abs(D[j] - D[i]) >= K, range(i + 1, N))) for i in range(N)]
	print(N - sum(map(lambda i: hung(i, i), range(N))))