#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int u,m,dis[N],cnt,sum[N],T,n,head[N],vis[N];
struct qedge{
int to,next,quan;
}edge[N * 2];
void add(int x,int y,int z){
edge[++cnt].to = y;
edge[cnt].quan = z;
edge[cnt].next = head[x];
head[x] = cnt;
}
void spfa(){
memset(vis,0,sizeof vis);
memset(head,-1,sizeof head);
memset(dis,10000,sizeof dis);
memset(sum,0,sizeof sum);
queue<int> q;
vis[1] = 1;
dis[1] = 0;
q.push(1);
sum[1]++;
while(!q.empty()){
u = q.front();
vis[u] = 0;
q.pop();
for(int i = head[u];i;i = edge[i].next){
int v = edge[i].to;
if(dis[v] > dis[u] + edge[i].quan){
dis[v] = dis[u] + edge[i].quan;
if(!vis[v]){
vis[v] = 1;
q.push(v);
sum[v]++;
if(sum[v] > n){
cout<<"YES"<<endl;
return ;
}
}
}
}
}
cout<<"NO"<<endl;
}
int main(int argc, char** argv) {
cin>>T;
while(T--){
memset(edge,0,sizeof edge);
cin>>n>>m;
for(int i = 1;i <= m;i++){
int a,b,w;
cin>>a>>b>>w;
if(w >= 0) add(a,b,w),add(b,a,w);
else add(a,b,w);
}
spfa();
cnt = 0;
}
return 0;
}