#include<bits/stdc++.h>
using namespace std;
int n,tc,TM,a[111],b[111],c[111];
bool check(int misu)
{
for(int i=1;i<=n;i++)
{
int p=(a[i]-b[i])*tc;
int w=c[i]-b[i]*(TM+tc-misu);
if(p<w)return false;
}
return true;
}
int main()
{
int g;
cin>>g;
while(g--)
{
cin>>n>>tc>>TM;
for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
int l=0,r=tc+TM+10,mid;
while(l<=r)
{
mid=(l+r)/2;
if(check(mid))r=mid-1;
else l=mid+1;
}
cout<<mid<<endl;
}
return 0;
}