#include <bits/stdc++.h>

#define X first
#define Y second
#define PB push_back
#define x first
#define y second
#define pb push_back
#define all(a) begin(a),end(a)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N=300010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int t,n,k;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>t;
	while (t--)
	{
		cin>>n>>k;
		int a=0;
		multiset<int> ms;
		for (int i=0;i<n;++i)
		{
			int x;
			cin>>x;
			if (x>=k) ++a;
			else ms.insert(x);
		}
		int x=0;
		while (x<(n+1)/3 && ms.size()>=2)
		{
			int r=*ms.begin();
			ms.erase(ms.begin());
			auto it=ms.lower_bound(k-r);
			if (it==ms.begin()) break;
			--it;
			ms.erase(it);
			++x;
		}
		if (x>=(n+1)/3) cout<<(n-1)/3<<en;
		else cout<<x+max(a-x-1,(n-3*x-1)/2)<<en;
	}
}