There are $n$ points on a plane. The $i$-th point has coordinates $(x_i, y_i)$. You have two horizontal platforms, both of length $k$. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same $y$-coordinate) and have integer borders. If the left border of the platform is $(x, y)$ then the right border is $(x + k, y)$ and all points between borders (including borders) belong to the platform.

Note that platforms can share common points (overlap) and it is not necessary to place both platforms on the same $y$-coordinate.

When you place both platforms on a plane, all points start falling down decreasing their $y$-coordinate. If a point collides with some platform at some moment, the point stops and is saved. Points which never collide with any platform are lost.

Your task is to find the maximum number of points you can save if you place both platforms optimally.

You have to answer $t$ independent test cases.

For better understanding, please read the Note section below to see a picture for the first test case.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$; $1 \le k \le 10^9$) — the number of points and the length of each platform, respectively. The second line of the test case contains $n$ integers $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^9$), where $x_i$ is $x$-coordinate of the $i$-th point. The third line of the input contains $n$ integers $y_1, y_2, \dots, y_n$ ($1 \le y_i \le 10^9$), where $y_i$ is $y$-coordinate of the $i$-th point. All points are distinct (there is no pair $1 \le i < j \le n$ such that $x_i = x_j$ and $y_i = y_j$).

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer: the maximum number of points you can save if you place both platforms optimally.


-----Example-----
Input
4
7 1
1 5 2 3 1 5 4
1 3 6 7 2 5 4
1 1
1000000000
1000000000
5 10
10 7 5 15 8
20 199 192 219 1904
10 10
15 19 8 17 20 10 9 2 10 19
12 13 6 17 1 14 7 9 19 3

Output
6
1
5
10



-----Note-----

The picture corresponding to the first test case of the example:

[Image]

Blue dots represent the points, red segments represent the platforms. One of the possible ways is to place the first platform between points $(1, -1)$ and $(2, -1)$ and the second one between points $(4, 3)$ and $(5, 3)$. Vectors represent how the points will fall down. As you can see, the only point we can't save is the point $(3, 7)$ so it falls down infinitely and will be lost. It can be proven that we can't achieve better answer here. Also note that the point $(5, 3)$ doesn't fall at all because it is already on the platform.

Difficulty: introductory

Starter code:

Solutions:
import bisect

def solve(n,x_coords,y_coords,k,ans):
    x_coords.sort()
    dp = []
    for i in range(n):
        x = x_coords[i]
        index = bisect.bisect(x_coords,x+k)-1
        dp.append(index-i+1)

    dp_max = []
    for i in reversed(dp):
        if not dp_max:
            dp_max.append(i)
        else:
            dp_max.append(max(dp_max[-1],i))

    dp_max.reverse()
    max_val = 0
    for i in range(n):
        x = x_coords[i]
        index = bisect.bisect(x_coords,x+k)-1
        val = index-i+1
        if index+1 < n:
            val += dp_max[index+1]

        max_val = max(max_val,val)

    ans.append(str(max_val))

def main():
    t = int(input())
    ans = []
    for i in range(t):
        n,k = list(map(int,input().split()))
        x_coords = list(map(int,input().split()))
        y_coords = list(map(int,input().split()))
        solve(n,x_coords,y_coords,k,ans)

    print('\n'.join(ans))

    
main()


class SortedList:
    def __init__(self, iterable=[], _load=200):
        """Initialize sorted list instance."""
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._mins = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        """Build a fenwick tree instance."""
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        """Update `fen_tree[index] += value`."""
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        """Return `sum(_fen_tree[:end])`."""
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        """Delete value at the given `(pos, idx)`."""
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        """Return an index pair that corresponds to the first position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        """Return an index pair that corresponds to the last position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        """Add `value` to sorted list."""
        _load = self._load
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        """Remove `value` from sorted list if it is a member."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        """Remove `value` from sorted list; `value` must be a member."""
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        """Remove and return value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        """Return the first index to insert `value` in the sorted list."""
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        """Return the last index to insert `value` in the sorted list."""
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        """Return number of occurrences of `value` in the sorted list."""
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        """Return the size of the sorted list."""
        return self._len

    def __getitem__(self, index):
        """Lookup value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        """Remove value at `index` from sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        """Return true if `value` is an element of the sorted list."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        """Return an iterator over the sorted list."""
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        """Return a reverse iterator over the sorted list."""
        return (value for _list in reversed(self._lists) for value in reversed(_list))

    def __repr__(self):
        """Return string representation of sorted list."""
        return 'SortedList({0})'.format(list(self))

t = int(input())

for _ in range(t):
    n,k = map(int,input().split())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    
    s = SortedList(xs)
    saved = [None]*n
    for i,x in enumerate(s):
        saved[i] = s.bisect_right(x+k)-s.bisect_left(x)
    #print(s)
    #print(saved)
    base = 1
    while base<n:
        base*=2
    tree = [0]*base + saved + [0]*(base-n)
    for i in range(base-1,0,-1):
        tree[i] = max(tree[2*i],tree[2*i+1])
    
    def query(a,b):
        a+=base
        b+=base
        m = 0
        while a<b:
            if a%2==1:
                m = max(m, tree[a])
                a+=1
            if b%2==1:
                m = max(m, tree[b-1])
                b-=1
            a//=2
            b//=2
        return m
    
    m = 0
    for i in range(n):
        #print(i,s[i],saved[i] + query(i+saved[i], n))
        m = max(m,saved[i] + query(i+saved[i], n))
    print(m)

from bisect import bisect_left as lower_bound,bisect_right as upper_bound
for _ in range(int(input())):
    n,k=map(int,input().split())
    x=sorted(map(int,input().split()))
    input()
    mxr=[0]*n
    for i in range(n-1,-1,-1):
        mxr[i]=i-lower_bound(x,x[i]-k)+1
    ans=1
    cmxr=mxr[0]
    for i in range(1,n):
        res=cmxr
        cmxr=max(cmxr,mxr[i])
        cf=upper_bound(x,x[i]+k)-i
        ans=max(ans,res+cf)
    print(ans)

'''
1
7 1
1 5 2 3 1 5 4

'''

from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

from itertools import accumulate
from functools import lru_cache


M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
 
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]


class Node:
    def __init__(self,s,e):
        self.start=s
        self.end=e
        self.val = 0
        self.left=None
        self.right=None
 
def build(nums,l,r):
    if l == r:
        temp = Node(l,l)
        temp.val = nums[l]
    else:
        mid=(l+r)>>1
        temp=Node(l,r)
        temp.left=build(nums,l,mid)
        temp.right=build(nums,mid+1,r)
        temp.val = max(temp.left.val,temp.right.val)
    return temp

def update(root,start,value):
    if root.start == start == root.end:
        root.val = value
    elif root.start <= start and root.end >= start:
        update(root.left,start,value)
        update(root.right,start,value)
        root.val = max(root.left.val,root.right.val)





def query(root,start,end):
    if root.start>=start and root.end<=end:return root.val
    elif root.start>end or root.end<start:return -float('inf')
    else:
        temp1 = query(root.left,start,end)
        temp2 = query(root.right,start,end)
        return max(temp1,temp2)

for _ in range(val()):
    n, k = li()
    l = li()
    y = li()

    l.sort()
    
    dp = [0] * (n + 1)

    for i in range(n - 1, -1, -1):
        curright = br(l, l[i] + k)
        totnow = curright - i
        dp[i] = totnow
    

    # print(l, k)
    # print(dp)

    root = build(dp, 0, n)


    for i in range(n):
        curright = br(l, l[i] + k)
        dp[i] += query(root, curright, n)
    print(max(dp))

import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = int(1e9) + 7
INF=2**32

def cal(n):
    ans=0
    while n:
        ans+=n%10
        n//=10
    return ans

for t in range(int(data())):
   n,k=mdata()
   ans=1
   X=sorted(mdata())
   Y=mdata()
   q=deque()
   d=dd(int)
   m=0
   for i in range(n):
        while q and X[i]-k>q[0]:
            m=max(m,d[q.popleft()])
        q.append(X[i])
        d[X[i]]=len(q)
        ans=max(ans,m+len(q))
   out(ans)


import bisect
from collections import deque
from sys import stdin
tt = int(stdin.readline())

for loop in range(tt):

    n,k = map(int,stdin.readline().split())
    x = list(map(int,stdin.readline().split()))
    y = list(map(int,stdin.readline().split()))

    x.sort()
    unAB = deque([])
    nmax = 0
    ans = 0

    for i in range(n):

        while len(unAB) > 0 and unAB[0][0] < x[i]-k:
            tx,val = unAB.popleft()
            nmax = max(nmax , val)

        ind = bisect.bisect_right(x,x[i]+k)
        val = ind - i
        ans = max(ans , nmax + val)
        unAB.append((x[i],val))

    print (ans)

import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br


"""
Facts and Data representation
Constructive? Top bottom up down
"""
def solve():
  n, k = I()
  a = I()
  y = I()
  a.sort()
  max_till = [0] * (2 * n)  
  ans = 0
  for i in range(n - 1, -1, -1):
    left, right = a[i], a[i] + k
    idxR = br(a, right)
    idxL = bl(a, left)
    cur = (idxR - idxL)
    max_till[i] = max(max_till[i + 1], cur)
    ans = max(ans, cur + max_till[idxR])
  print(ans)

t, = I()
while t:
  t -= 1
  solve()

"""
NTC here
"""


def iin(): return int(input())


def lin(): return list(map(int, input().split()))


def main():
    from bisect import bisect_right as br, bisect_left as bl
    t = iin()
    while t:
        t-=1 
        n, k = lin()
        x = lin()
        y = lin()
        x.sort()
        sol = []
        for i in range(n):
            val = x[i] + k
            pos = br(x, val)
            sol.append([x[i], pos-i])
        # print(sol)
        s1 = [i for i, j in sol]
        a1 = [j for i, j in sol]
        for i in range(n-2, -1, -1):a1[i] = max(a1[i], a1[i+1])
        # print(a1, s1)
        ans = max(sol, key=lambda x: x[1])[1]
        for i in range(n):
            val, count = sol[i]
            pos = bl(s1, val+k+1)
            if pos<n:
                # print(count, a1[pos], ans)
                ans = max(count + a1[pos], ans)
        print(ans)

main()

import bisect
t=int(input())
for you in range(t):
    l=input().split()
    n=int(l[0])
    k=int(l[1])
    l=input().split()
    li=[int(i) for i in l]
    l=input()
    li.sort()
    dp=[[0 for i in range(2)]for i in range(n)]
    maxas=[0 for i in range(n)]
    dp[-1][0]=1
    dp[-1][1]=1
    maxas[-1]=1
    for i in range(n-2,-1,-1):
        if(li[i]+k>=li[-1]):
            dp[i][0]=n-i
            dp[i][1]=n-i
            maxas[i]=max(maxas[i+1],dp[i][0])
            continue
        z=bisect.bisect_right(li,li[i]+k)
        dp[i][0]=z-i
        maxas[i]=max(maxas[i+1],dp[i][0])
        dp[i][1]=z-i+maxas[z]
    maxa=0
    for i in range(n):
        maxa=max(maxa,dp[i][0])
        maxa=max(maxa,dp[i][1])
    print(maxa)



import bisect 

for _ in range(int(input())):
    
    n, k = map(int, input().split())
    
    x = list(map(int, input().split()))
    y = input()
    x.sort()
    X = [bisect.bisect_right(x, x[i] + k) for i in range(n)]
    Y = [0]
    for i in range(n - 1, -1, -1):
        Y += [max(Y[-1], X[i] - i)]
    Y.reverse()
    ans = 0
    for i in range(n):
        ans = max(ans, X[i] - i + Y[X[i]])
    print(ans)