#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1000000 + 20;
int att[maxn];
int fre[maxn];
int wait[maxn];
void work() {
int HP, hurt;
int MYHP, m;
scanf("%d%d%d%d", &HP, &hurt, &MYHP, &m);
int mx = -inf;
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d", &att[i], &fre[i], &wait[i]);
mx = max(mx, att[i]);
}
int need = MYHP / hurt + ((MYHP % hurt) > 0);
for (int i = 1; i <= m; ++i) {
int dis = wait[i] - fre[i];
if (dis == 0 && att[i] == 0) continue;
if (dis == 0 && att[i] != 0) {
printf("YES\n");
return;
}
if (dis < 0 && mx != 0) {
printf("YES\n");
return;
}
if (dis < 0 && mx == 0) {
continue;
}
int how = need / dis + ((need % dis) > 0);
// printf("%d*****\n", how);
int cut = (how - 1) * att[i] + mx;
if (cut >= HP) {
printf("YES\n");
return;
}
// cout << cut << endl;
}
printf("NO\n");
return;
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return 0;
}