#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
double eps = 1E-6;

bool eq(double a, double b)
{
	return fabs(a - b) < eps;
}

struct Segment
{
	double d, l, h;
}segs[1010];

bool operator <(Segment a, Segment b)
{
	return a.l < b.l;
}

int main()
{
	freopen("bus.in", "r", stdin);
	//freopen("bus.out", "w", stdout);
	int test, i;
	scanf("%d", &test);
	while(test > 0)
	{
		int resSpeed = 0;
		double len = 0, resTime = 1E12, h = 0;
		scanf("%d%d", &n, &m);
		for(i = 0; i < n; i++)
		{
			scanf("%lf%lf%lf", &segs[i].d, &segs[i].l, &segs[i].h);
			len += segs[i].d;
		}
		segs[n].d = 0;
		segs[n].h = 0;
		segs[n].l = m;
		n++;
		sort(segs, segs + n);

		for(i = 0; i < n; i++)
		{
			if(segs[i].l > m)
				break;

			double t = len / segs[i].l + h;

			if(!eq(resTime, t) && t < resTime)
			{
				resTime = t;
				resSpeed = segs[i].l;
			}
			
			h += segs[i].h;

			i++;

			while(i < n && segs[i].l == segs[i - 1].l)
			{
				h += segs[i].h;
				i++;
			}
			i--;
		}

		printf("%d\n", resSpeed);

		test--;
	}
	return 0;
}
