Read problems statements in Mandarin Chinese and Russian as well. 

Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D.
Find out maximum possible sum of all good disjoint pairs that can be made from these numbers.
Sum of X pairs is the sum of all 2*X numbers in the pairs.

------ Input ------ 

First line contains T, the number of test cases to follow.
First line of each test case contains 2 space separated integers: N and D.
Second line of each test case contains N space separated integers.

------ Output ------ 

For each test case, output the answer in a separate line.

------ Constraints ------ 

$1 ≤ T, N, D, Array Elements ≤ 10^{5}$
$1 ≤ Sum of N over all test cases ≤ 5*10^{5}$

------ Note: ------ 
 
Pair (a,b) is disjoint with pair (c,d) if and only if indices of a, b, c and d in the array are distinct.

----- Sample Input 1 ------ 
3
3 3
3 5 8
4 3
5 8 10 12
5 3
3 2 8 17 15
----- Sample Output 1 ------ 
8
22
37
----- explanation 1 ------ 
Test Case 1: You can only take 1 pair out of 3 numbers. So pair(3,5) is only valid pair whose difference is 2.  

Test Case 3: You can take pairs(3,2) and (15,17) as the answer.

Difficulty: MEDIUM_HARD

Solutions:
for _ in range(int(input())):
	(N, D) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	i = N - 1
	sm = 0
	while i > 0:
		if array[i] - array[i - 1] < D:
			sm += array[i] + array[i - 1]
			i -= 2
		else:
			i -= 1
	print(sm)


test = int(input())
for _ in range(test):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	b = sorted(a)
	i = n - 1
	while i >= 1:
		if b[i] - b[i - 1] < d:
			s += b[i] + b[i - 1]
			i -= 2
		else:
			i -= 1
	print(s)


for t in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	i = 1
	ans = 0
	while 1:
		if i > n - 1:
			break
		elif a[i - 1] - a[i] < d:
			ans = ans + a[i - 1] + a[i]
			i = i + 2
		else:
			i = i + 1
	print(ans)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 0
	i = n - 1
	while i >= 1:
		if arr[i] - arr[i - 1] < d:
			ans += arr[i] + arr[i - 1]
			i -= 2
		else:
			i -= 1
	print(ans)


for t in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a, reverse=True)
	ans = 0
	i = 0
	while i < n - 1:
		if a[i] - a[i + 1] < d:
			ans += a[i] + a[i + 1]
			i += 2
		else:
			i += 1
	print(ans)


t = int(input())
for T in range(t):
	(n, d) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort(reverse=True)
	(ind, ind1) = (0, 1)
	ans = []
	while ind < n - 1:
		if a[ind] - a[ind + 1] < d:
			ans.append(a[ind])
			ans.append(a[ind + 1])
			ind += 2
			continue
		ind += 1
	print(sum(ans))


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	i = n - 1
	s = 0
	while i >= 1:
		if l[i] - l[i - 1] < d:
			s += l[i] + l[i - 1]
			i -= 2
		else:
			i -= 1
	print(s)


from sys import stdin, stdout

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
t = int(sin())
from bisect import bisect_left
for _ in range(t):
	(n, d) = listInput()
	li = listInput()
	li.sort()
	ans = 0
	i = n - 1
	while i > 0:
		if li[i] - li[i - 1] < d:
			ans += li[i] + li[i - 1]
			i -= 2
		else:
			i -= 1
	print(ans)


T = int(input())
for _ in range(T):
	(n, d) = map(int, input().split())
	L = list(map(int, input().split()))
	L.sort(reverse=True)
	ans = 0
	i = 0
	while i < n - 1:
		if L[i] - L[i + 1] < d:
			ans += L[i] + L[i + 1]
			i += 2
		else:
			i += 1
	print(ans)


T = int(input())
for i in range(T):
	sum1 = 0
	(N, D) = map(int, input().split())
	s = list(map(int, input().split()))
	s.sort()
	j = N - 1
	while j > 0:
		if s[j] - s[j - 1] < D:
			sum1 += s[j] + s[j - 1]
			j -= 2
		else:
			j -= 1
	print(sum1)


t = int(input())
for x in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	p1 = 0
	p2 = 1
	sums = 0
	p = l[:]
	l.sort()
	i = n - 1
	flag = 0
	i = n - 1
	j = i - 1
	iprev = -20
	while j >= 0 and len(l) > 1:
		if abs(l[i] - l[j]) < d:
			sums += l[i] + l[j]
			l.pop(-1)
			l.pop(-1)
			i = len(l) - 1
			j = i - 1
		else:
			l.pop(-1)
			i = len(l) - 1
			j = i - 1
	print(sums)


for x in range(int(input())):
	(n, d) = map(int, input().split())
	li = list(map(int, input().split()))
	li = sorted(li)[::-1]
	j = 0
	ans = 0
	while j < n - 1:
		if li[j] - li[j + 1] < d:
			ans += li[j] + li[j + 1]
			j += 2
		else:
			j += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, p) = map(int, input().split())
	flag = 0
	sum = 0
	l = list(map(int, input().split()))
	l.sort()
	for i in range(n - 1, 0, -1):
		if flag == 1:
			flag = 0
			continue
		elif abs(l[i] - l[i - 1]) < p:
			sum = sum + l[i] + l[i - 1]
			flag = 1
	print(sum)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	numbers = [int(number) for number in input().split()]
	numbers.sort()
	result = 0
	i = n - 1
	while i > 0:
		if numbers[i] - numbers[i - 1] < d:
			result += numbers[i] + numbers[i - 1]
			i -= 2
		else:
			i -= 1
	print(result)


def sumpair(n, d, arr):
	arr.sort()
	i = n - 1
	s = 0
	while i > 0:
		if arr[i] - arr[i - 1] < d:
			s += arr[i - 1] + arr[i]
			i -= 2
		else:
			i -= 1
	return s
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(sumpair(n, d, arr))


for t in range(int(input())):
	temp = list(map(int, input().split()))
	n = temp[0]
	d = temp[1]
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	ans = 0
	if n == 1:
		print(0)
		continue
	p1 = 0
	p2 = 1
	ans = 0
	while p1 < n and p2 < n:
		if a[p1] - a[p2] < d:
			ans += a[p1] + a[p2]
			p1 = p2 + 1
			p2 = p1 + 1
			continue
		else:
			p1 = p2 + 1
			if p1 > p2:
				tt = p1
				p1 = p2
				p2 = tt
	print(ans)


t = int(input())
for i in range(t):
	C = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	a = C[0] - 1
	sum = 0
	while a > 0:
		if A[a] - A[a - 1] < C[1]:
			sum += A[a] + A[a - 1]
			a -= 1
		a -= 1
	print(sum)


from bisect import bisect_left
from heapq import heapify, heappush, heappop
from collections import deque
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
for _ in range(ii()):
	(n, d) = il()
	arr = il()
	ans = 0
	arr.sort()
	i = n - 1
	while i >= 1:
		if arr[i] - arr[i - 1] < d:
			ans += arr[i] + arr[i - 1]
			i -= 2
		else:
			i -= 1
	print(ans)


TC = int(input())
for _ in range(TC):
	(N, D) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	arr.sort(reverse=True)
	total = 0
	i = 1
	while i < N:
		if arr[i - 1] - arr[i] < D:
			total += arr[i] + arr[i - 1]
			i += 1
		i += 1
	print(total)


t = int(input())
for I in range(t):
	(n, d) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	sum1 = 0
	i = n - 1
	while i > 0:
		if a[i] - a[i - 1] < d:
			sum1 += a[i] + a[i - 1]
			i -= 2
		else:
			i -= 1
	print(sum1)


t = int(input())
while t != 0:
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	b = sorted(a)
	i = n - 1
	while i >= 1:
		if b[i] - b[i - 1] < d:
			s += b[i] + b[i - 1]
			i -= 2
		else:
			i -= 1
	print(s)
	t -= 1


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=False)
	ans = 0
	index = n - 1
	while index > 0:
		if arr[index] - arr[index - 1] < d:
			ans += arr[index] + arr[index - 1]
			index -= 2
		else:
			index -= 1
	print(ans)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	nli = list(map(int, input().split()))
	nli.sort(reverse=True)
	lst = list()
	ind = 0
	while ind < n - 1:
		if nli[ind] - nli[ind + 1] < d:
			lst.append(nli[ind + 1])
			lst.append(nli[ind])
			ind += 2
		else:
			ind += 1
	print(sum(lst))


t = int(input())
while t:
	t -= 1
	(n, d) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	a.reverse()
	i = 1
	ans = 0
	while i < n:
		if a[i - 1] - a[i] < d:
			ans += a[i] + a[i - 1]
			i += 2
		else:
			i += 1
	print(ans)


from typing import List

def soln(n: int, d: int, arr: List[int]) -> int:
	arr.sort(reverse=True)
	res = 0
	i = 0
	while i < n - 1:
		if arr[i] - arr[i + 1] < d:
			res += arr[i] + arr[i + 1]
			i += 1
		i += 1
	return res
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(soln(n, d, arr))


for _ in range(int(input())):
	(N, D) = map(int, input().split())
	array = sorted(map(int, input().split()), reverse=True)
	i = 0
	ans = 0
	while i + 1 < N:
		if array[i] - array[i + 1] < D:
			ans += array[i] + array[i + 1]
			i += 1
		i += 1
	print(ans)


for _ in range(int(input())):
	(N, D) = list(map(int, input().split()))
	L = list(map(int, input().split()))
	L.sort(reverse=True)
	sum_ = 0
	flag = 0
	for i in range(N - 1):
		if flag == 1:
			flag = 0
		elif L[i] - L[i + 1] < D:
			sum_ += L[i] + L[i + 1]
			flag = 1
	print(sum_)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	i = 0
	s = 0
	while i < n - 1:
		if a[i] - a[i + 1] < d:
			s += a[i] + a[i + 1]
			i = i + 2
		else:
			i += 1
	print(s)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	taken = 0
	Sm = 0
	for i in range(n - 1):
		if taken == 0:
			if arr[i] - arr[i + 1] < d:
				Sm = Sm + arr[i] + arr[i + 1]
				taken = 1
		elif taken == 1:
			taken = 0
	print(Sm)


t = int(input())
for t0 in range(t):
	(n, d) = [int(i) for i in input().strip().split(' ')]
	li = [int(i) for i in input().strip().split(' ')]
	li.sort(reverse=True)
	sm = 0
	i = 0
	while i < n - 1:
		if li[i] - li[i + 1] < d:
			sm += li[i] + li[i + 1]
			i += 1
		i += 1
	print(sm)


for T in range(int(input())):
	(N, D) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	mark = [0] * N
	ans = 0
	for i in range(N - 1, 0, -1):
		if mark[i] == 0:
			if arr[i] - arr[i - 1] < D:
				ans += arr[i] + arr[i - 1]
				(mark[i], mark[i - 1]) = (1, 1)
	print(ans)


T = int(input())
for i in range(T):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l = l[::-1]
	(s, i) = (0, 1)
	while i < n:
		if l[i - 1] - l[i] < d:
			s += l[i] + l[i - 1]
			i += 1
		i += 1
	print(s)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	l.sort(reverse=True)
	ans = 0
	i = 0
	j = 1
	while j < n:
		if l[i] - l[j] < d:
			ans += l[i] + l[j]
			j += 2
			i += 2
		else:
			i += 1
			j += 1
	print(ans)


t = int(input())
for j in range(0, t):
	(n, d) = input().strip().split()
	n = int(n)
	d = int(d)
	a = list(map(int, input().strip().split()))
	a.sort(reverse=True)
	add = 0
	i = 0
	while i < n - 1:
		if a[i] - a[i + 1] < d:
			add = add + a[i] + a[i + 1]
			i = i + 2
		else:
			i = i + 1
	print(add)


a = int(input())
for i in range(0, a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	d.sort(reverse=True)
	u = 0
	z = []
	for t in range(0, b):
		z.append(0)
	for t in range(0, b):
		if z[t] == 0:
			z[t] = 1
			for y in range(t + 1, b):
				r = abs(d[t] - d[y])
				if r < c and z[y] == 0:
					u = u + (d[t] + d[y])
					z[y] = 1
					break
				elif r >= c:
					break
	print(u)


for j in range(int(input())):
	(n, d) = map(int, input().split())
	x = list(map(int, input().split()))
	x.sort()
	x.reverse()
	i = 1
	c = 0
	while i < n:
		if x[i - 1] - x[i] < d:
			c += x[i - 1] + x[i]
			i += 2
		else:
			i += 1
	print(c)