#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define INF 1e12
#define int long long
using namespace std;
const int N = 3e3 + 10, M = 6e3 + 10;
int T , n , m , cnt[N] , head[N] , l , dist[N];
bool flag[N];
struct e{
int u , v , w , nxt;
} fs[M];
void add(int u , int v , int w) {
fs[++ l] = {u , v , w , head[u]};
head[u] = l;
}
bool spfa(int s) {
queue <int> q;
dist[s] = 0;
flag[s] = 1;
q.push(s);
cnt[s] ++;
while(!q.empty()) {
int t = q.front();
q.pop();
flag[t] = 0;
for(int i = head[t]; i ;i = fs[i].nxt){
int j = fs[i].v;
int cost = fs[i].w;
if(dist[j] > dist[t] + cost) {
dist[j] = dist[t] + cost;
if(!flag[j]) {
flag[j] = 1;
cnt[j] ++;
if(cnt[j] >= n) return 1;
q.push(j);
}
}
}
}
return 0;
}
signed main() {
IOS;
for(cin >> T; T ;-- T) {
l = 0;
for(int i = 1;i <= n;++ i) {
head[i] = 0;
cnt[i] = 0;
flag[i] = 0;
dist[i] = INF;
}
cin >> n >> m;
for(int i = 1;i <= m;++ i){
int u , v , w;
cin >> u >> v >> w;
if(w >= 0) {
add(u , v , w);
add(v , u , w);
}
else add(u , v , w);
}
if(spfa(1)) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}