#include <stdio.h>
#include <iostream>
#include <map>

using namespace std;

int main()
{
	freopen("bus.in", "r", stdin);
	//freopen("bus.out", "w", stdout);

	int test;
	cin >> test;

	int d[1000 + 100];
	int l[1000 + 100];
	int h[1000 + 100];

	for(int tt=0; tt<test; tt++)
	{
		int n, m;
		int len = 0;

		cin >> n >> m;
		for(int i=0; i<n; i++)
		{
			cin >> d[i] >> l[i] >> h[i];
			len += d[i];
		}


		double restime = 1e12;
		int resspeed;
		for(int speed=1; speed<=m; speed++)
		{
			double time = 0;
			for(int i=0; i<n; i++)
			{
				if (speed > l[i])
				{
					time += h[i];
				}
			}
			time += 1.0*len / speed;

			if (time < restime || (time == restime))
			{
				resspeed = speed;
				restime = time;
			}
		}	

		cout << resspeed << endl;
		
	}

	return 0;
}