#include <iostream>
#include <set>
#include <fstream>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;

const double EPS = 0.00000000000001;

void test(int segments)
{
	int M = (rand() % 100000) + 1;
	cout <<segments <<" " <<  M<<endl;
	for (int i = 0;i < segments;i++)
		cout <<(rand() % 1000) + 1 << " " << (rand() % M) + 1 << " " <<rand() % 1001 <<endl;
}

void test2(int segments)
{
	int M = 90001 + (rand() % 10000);
	cout <<segments <<" " <<  M<<endl;
	for (int i = 0;i < segments;i++)
		cout <<(i % 5 == 0 ? (rand() % 1000) + 1 : rand() % 50 + 1)<< " " << (i % 3 == 0 ? (90001 + (rand() % 10000)) : (rand()%20 + 1))<< " " <<(i % 2 == 0 ? (rand() % 1001 ) : (rand() % 10)) <<endl;
}

void test3(int segments)
{
	int M = 90001 + (rand() % 10000);
	cout <<segments <<" " <<  M<<endl;
	for (int i = 0;i < segments;i++)
		cout <<(i % 5 == 0 ? (rand() % 1000) + 1 : rand() % 50 + 1)<< " " << 90001 + (rand() % 10000)<< " " <<(i % 2 == 0 ? (rand() % 1001 ) : (rand() % 10)) <<endl;
}

void generate_testcases()
{
	srand(clock());

	int tc = 20;

	freopen("bus.out.new", "w", stdout);
	
	/*
	test2(1000);
	test2(999);

	for (int cc = 0;cc< tc;cc++)
		test2((rand() % 1000) + 1);

	for (int cc = 0;cc < 5;cc++)
		test2((rand() % 5) + 1);
		*/

	test3(1000);
	test3(1000);
	test3(1000);
	test3(1000);
}

void main()
{
//	generate_testcases();
//	return;

	int tc;
	freopen("bus.in", "r", stdin);
	
	cin >>tc;
	assert(0 <= tc && tc <= 100);

	for (int cc = 0;cc < tc;cc++)
	{
		int N, M;
		cin >>N >>M;
		assert(1 <= N && N <= 1000);
		assert(1 <= M && M <= 100000);

		vector<int> D, L, H;
		D.resize(N, 0);
		L = H = D;
		set<int> speeds;
		speeds.insert(M);

		for (int i = 0;i < N;i++)
		{
			cin >> D[i] >>L[i] >>H[i];
			assert(1 <= D[i] && D[i] <= 1000);
			assert(1 <= L[i] && L[i] <= 100000);
			assert(0 <= H[i] && H[i] <= 1000);

			if (L[i] < M)
				speeds.insert(L[i]);
		}

		double lowestTime = INT_MAX;
		int maxSpeed = 0;
		// try all speeds
		for (set<int>::iterator it = speeds.begin();it != speeds.end();it++)
		{
			int s = *it;

			double curTime = 0;
			for (int i = 0;i < N;i++)
			{
				curTime += (double)D[i] / (double)s + (double)(s > L[i] ? H[i] : 0);
			}

			if (s > maxSpeed && (curTime < lowestTime + EPS))
			{
				lowestTime = curTime;
				maxSpeed = s;
			}
		}

		cout <<maxSpeed <<endl;
	}
}
