#include <bits/stdc++.h>
using namespace std;
ifstream f("text.in");
ofstream g("text.out");
const int nmax = 200009;
int v[nmax], mx[nmax], in[nmax], arr[nmax];
void solve() {
  int n, t;
  cin >> n >> t;
  for (int i = 1; i <= n; i++) cin >> v[i];
  char s[30];
  for (int i = 1; i <= n; i++) cin >> s;
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= n; i++) {
    int p = i;
    for (int mid, left = 1, right = i; left <= right;) {
      mid = (left + right) / 2;
      if (v[i] - v[mid] <= t)
        p = mid, right = mid - 1;
      else
        left = mid + 1;
    }
    in[i] = p;
    arr[i] = i - p + 1;
  }
  mx[1] = arr[1];
  for (int i = 2; i <= n; i++) mx[i] = max(arr[i], mx[i - 1]);
  int result = 0;
  for (int i = 1; i <= n; i++) {
    int res = arr[i];
    if (in[i] - 1 != 0) res += mx[in[i] - 1];
    result = max(result, res);
  }
  cout << result << '\n';
}
int main() {
  int tasks;
  cin >> tasks;
  while (tasks--) solve();
  return 0;
}
