//Time 250ms, Memory 332K
#include<iostream>
#include<cstring>
using namespace std;
int cnt,n,m1,m2;
struct point
{
int a,b;
double t;
point(int a=0,int b=0,double t=0.0):a(a),b(b),t(t){}
}p[6000];
int bellman()
{
int i,j;
int flag;
double dis[505];
for(i=0;i<n;i++) dis[i]=10001;
for(i=1;i<n;i++)
{
flag=0;
for(j=0;j<cnt;j++)
{
if(dis[p[j].b]>dis[p[j].a]+p[j].t)
{
dis[p[j].b]=dis[p[j].a]+p[j].t;flag=1;
}
}
if(!flag) break;
}
for(j=0;j<cnt;j++)
{
if(dis[p[j].b]>dis[p[j].a]+p[j].t) return 1;
}
return 0;
}
int main()
{
int i,a,b,f;
double t;
cin>>f;
while(f--)
{
cin>>n>>m1>>m2;
cnt=0;
for(i=0;i<m1;i++)
{
cin>>a>>b>>t;
p[cnt++]=point(a,b,t);
p[cnt++]=point(b,a,t);
}
for(i=0;i<m2;i++)
{
cin>>a>>b>>t;
p[cnt++]=point(a,b,-1.0*t);
}
if(bellman()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}