#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const int INF = 2147483647;
const int S = 1e5+5;
int n,m,tot;
int head[S],ver[S],edge[S],Next[S],dis[S],vis[S],v[S];
inline void add(int x,int y,int z)
{ver[++tot] = y,edge[tot] = z,Next[tot] = head[x],head[x] = tot;}
inline void spfA(int s)
{
memset(dis,0x7f,sizeof(dis));
memset(vis,0,sizeof(vis));
memset(v,0,sizeof(v));
queue <int> q;
while(!q.empty()) q.pop();
dis[s] = 0;
vis[s] = 1;
q.push(s);
while(!q.empty())
{
int x = q.front();
q.pop();
vis[x] = 0;
for(int i = head[x];i;i = Next[i])
{
int y = ver[i],z = edge[i];
if(dis[y] > dis[x]+z)
{
dis[y] = dis[x]+z;
if(!vis[y])
{
q.push(y);vis[y] = 1;
if(++v[x] >= n) {puts("YES");return;}
}
}
}
}
puts("NO");
}
inline LL read()
{
LL x=0,f=1;
char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') f = -1;ch = getchar();}
while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
return f*x;
}
int main(int argc,char *argv[])
{
int T = read();
while(T--)
{
int flag = 0;
n = read(),m = read();
while(m--)
{
int u = read(),v = read(),w = read();
if(w >= 0) add(u,v,w),add(v,u,w);
else add(u,v,w);
}
spfA(1);
}
return 0;
}