#include <bits/stdc++.h>
using namespace std;
#define int long long
const int LINF = (int)2e18;
const int mxN = (int)1e2+10;
int n, A, B, a[mxN], x[mxN], y[mxN], c[mxN];
bool works(int remA, int remB){
for(int i = 0; i < n; i++)
if((A-remA)*x[i] + (B-remB)*y[i] > c[i])
return false;
return true;
}
int bin(int remA){
int l = 0, r = B-1;
if(!works(remA,r) or remA<0 or remA>=A) return LINF;
while(l<r){
int mid = (l+r)/2;
if(works(remA, mid)) r=mid;
else l=mid+1;
}
return remA+l;
}
void solve(){
cin >> n >> A >> B; int ans = A+B-2;
for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> c[i];
for(int _ = 0; _ < 2; _++){
int l = 0, r = A-1;
while(r-l>3){
int m = (r-l)/3;
int X = bin(l+m), Y = bin(r-m);
if(X==LINF or X>Y) l+=m;
else r-=m;
}
for(int i = l; i <= r; i++)
ans = min(ans, bin(i));
swap(A,B);
for(int i = 0; i < n; i++) swap(x[i],y[i]);
}
cout << ans << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1; cin >> t;
while(t--) solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGludCBsb25nIGxvbmcKY29uc3QgaW50IExJTkYgPSAoaW50KTJlMTg7CmNvbnN0IGludCBteE4gPSAoaW50KTFlMisxMDsKaW50IG4sIEEsIEIsIGFbbXhOXSwgeFtteE5dLCB5W214Tl0sIGNbbXhOXTsKCmJvb2wgd29ya3MoaW50IHJlbUEsIGludCByZW1CKXsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspCiAgICAgICAgaWYoKEEtcmVtQSkqeFtpXSArIChCLXJlbUIpKnlbaV0gPiBjW2ldKQogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICByZXR1cm4gdHJ1ZTsKfQoKaW50IGJpbihpbnQgcmVtQSl7CiAgICBpbnQgbCA9IDAsIHIgPSBCLTE7CiAgICBpZighd29ya3MocmVtQSxyKSBvciByZW1BPDAgb3IgcmVtQT49QSkgcmV0dXJuIExJTkY7CiAgICB3aGlsZShsPHIpewogICAgICAgIGludCBtaWQgPSAobCtyKS8yOwogICAgICAgIGlmKHdvcmtzKHJlbUEsIG1pZCkpIHI9bWlkOwogICAgICAgIGVsc2UgbD1taWQrMTsKICAgIH0KICAgIHJldHVybiByZW1BK2w7Cn0KCnZvaWQgc29sdmUoKXsKICAgIGNpbiA+PiBuID4+IEEgPj4gQjsgaW50IGFucyA9IEErQi0yOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgY2luID4+IHhbaV0gPj4geVtpXSA+PiBjW2ldOwogICAgZm9yKGludCBfID0gMDsgXyA8IDI7IF8rKyl7CiAgICAgICAgaW50IGwgPSAwLCByID0gQS0xOwogICAgICAgIHdoaWxlKHItbD4zKXsKICAgICAgICAgICAgaW50IG0gPSAoci1sKS8zOwogICAgICAgICAgICBpbnQgWCA9IGJpbihsK20pLCBZID0gYmluKHItbSk7CiAgICAgICAgICAgIGlmKFg9PUxJTkYgb3IgWD5ZKSBsKz1tOwogICAgICAgICAgICBlbHNlIHItPW07CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaSA9IGw7IGkgPD0gcjsgaSsrKQogICAgICAgICAgICBhbnMgPSBtaW4oYW5zLCBiaW4oaSkpOwogICAgICAgIHN3YXAoQSxCKTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBzd2FwKHhbaV0seVtpXSk7CiAgICB9CiAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwp9CgppbnQzMl90IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZSgwKTsKCWludCB0ID0gMTsgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pIHNvbHZlKCk7Cn0K