### P6185 [NOI Online #1 提高组] 序列(二分图)

// Problem: P6185 [NOI Online #1 提高组] 序列// Contest: Luogu// URL: https://www.luogu.com.cn/problem/P6185// Memory Limit: 250 MB// Time Limit: 2000 ms// Date: 2022-05-23 16:17:16// --------by Herio--------#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned long long ull; const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;const int hashmod[4] = {402653189,805306457,1610612741,998244353};#define mst(a,b) memset(a,b,sizeof a)#define db double#define PII pair<int,int>#define PLL pair<ll,ll>#define x first#define y second#define pb emplace_back#define SZ(a) (int)a.size()#define rep(i,a,b) for(int i=a;i<=b;++i)#define per(i,a,b) for(int i=a;i>=b;--i)#define IOS ios::sync_with_stdio(false),cin.tie(nullptr) void Print(int *a,int n){  for(int i=1;i<n;i++)    printf("%d ",a[i]);  printf("%d\n",a[n]); }template <typename T>   //x=max(x,y)  x=min(x,y)void cmx(T &x,T y){  if(x<y) x=y;}template <typename T>void cmn(T &x,T y){  if(x>y) x=y;}int a[N],b[N];int n,m;int s[N];PII p[N];ll c[N];int find(int x){  return x==s[x]?x:s[x]=find(s[x]);}vector<int>e[N];int vis[N];ll sum[3];inline bool dfs(int u,int k){  vis[u] = k,sum[k]+=c[u];  int ok  = 1;  for(int v:e[u]){    if(vis[u]==vis[v]) ok = 0;    else if(!vis[v] && !dfs(v,3-k)) ok = 0;  }  return ok;}bool solve(){    scanf("%d%d",&n,&m);    rep(i,1,n) scanf("%d",&a[i]),c[i]=vis[i]= 0,s[i] = i ,e[i].clear();    rep(i,1,n) scanf("%d",&b[i]);    //printf("m=%d\n",m);    //return false;    map<PII,bool>mp;    int id = 0;    rep(i,1,m){      int op,x,y;      scanf("%d%d%d",&op,&x,&y);      //printf("%d,%d,%d\n",op,x,y);      //return false;      if(op==2) s[find(x)]=find(y);      else if(!mp[{x,y}]) mp[{x,y}]=1,p[++id] = {x,y};      //return false;    }        rep(i,1,n) c[find(i)]+=b[i]-a[i];    rep(i,1,id){      int x = p[i].x,y=p[i].y;      //printf("%d,%d\n",x,y);      x=find(x),y=find(y);      e[x].pb(y),e[y].pb(x);    }    rep(i,1,n){      if(i==find(i) && !vis[i]){        sum[1] = sum[2] = 0;        int ok = dfs(i,1);        //printf("i=%d ok=%d\n",i,ok);        if(ok && sum[1]!=sum[2]) return false;        if(!ok && ((sum[2]^sum[1]) &1) ) return false;      }    }   return true;}int main(){  int t;scanf("%d",&t);  //printf("t=%d\n",t);  while(t--){    puts(solve()?"YES":"NO");  }  return 0;}