#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; vector < int > d(n); for (int i = 0; i < n; i++) cin >> d[i]; sort(d.begin(), d.end()); d.pop_back(); n--; vector < bool > used(n, false); set < pair < int , int > > s; for (int i = 0; i < n; i++) s.insert(make_pair(d[i], i)); int cnt = 0; for (int i = n-1; i >= 0 && cnt*3 < n; i--) { if (used[i]) break; auto it = s.lower_bound(make_pair(k-d[i], 0)); if (it == s.begin()) continue; it = prev(it); cnt++; used[it->second] = true; used[i] = true; s.erase(it); } if (cnt*3 >= n) { cout << n/3 << "\n"; return; } int er = 0; for (int i = n-1; i >= 0 && er < cnt; i--) { if (!used[i]) { used[i] = true; er++; } } int rem = 0; for (int i = 0; i < n; i++) if (!used[i]) rem++; int cnt_l = 0; for (int i = 0; i < n; i++) { if (!used[i] && d[i] < k) cnt_l++; } if (cnt_l * 2 >= rem) { cout << cnt + rem/2 << "\n"; return; } else { cout << cnt + cnt_l + (rem - 2*cnt_l) << "\n"; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) solve(); }