#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(), x.end() #define ve vector #define vi vector<int> #define vvi vector<vector<int>> #define pb push_back using namespace std; template <class T> istream& operator >>(istream&in, vector<T>&v) { for(T&el : v) { in >> el; } return in; } template <class T> ostream& operator <<(ostream&out, vector<T>&v) { out <<"{"; for(T&el : v) { out << el << ' '; } out <<"}"; return out; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { int n, k; cin >> n >> k; vi ar(n); cin >> ar; sort(all(ar)); int cntb = 0; while (!ar.empty() && ar.back() >= k) { ++cntb; ar.pop_back(); } multiset<int> s(ar.begin(), ar.end()); int psm = 0, rest = 0; while (!s.empty()) { auto it = s.begin(); int x = *it; s.erase(it); if (s.empty()) { ++rest; } else { auto it1 = s.lower_bound(k - x); if (it1 != s.begin()) { ++psm; --it1; // cerr << "paired up " << x << " with " << *it1 << endl; s.erase(it1); } else ++rest; } } if (cntb >= psm + rest) { cout << cntb - 1 << "\n"; } else { int ans = 0; if (cntb >= psm) { cntb -= psm; ans += psm; ans += cntb; rest -= cntb; ans += (rest+1)/2 - 1; cout << ans << "\n"; } else { psm -= cntb; ans += cntb; if (rest >= psm) { ans += psm; rest -= psm; ans += (rest+1)/2-1; cout << ans << "\n"; } else { ans += rest; psm -= rest; ans += (2*psm+2)/3 - 1; cout << ans << "\n"; } } } } }