#include #include #include #include using namespace std; const int maxn=205; struct TwoSAT { int n,stk[maxn*2],mark[maxn*2],c; vector G[maxn*2]; void init(int nn) { n=nn; for(int i=0;i0) mark[stk[--c]]=0; if(!dfs(i+1)) return false; } } return true; } }alg; int T,n,m,hsh[128]; int main() { #ifdef local freopen("pro.in","r",stdin); #endif scanf("%d",&T); hsh['m']=0; hsh['h']=1; while(T-->0) { scanf("%d%d",&n,&m); alg.init(n); while(m-->0) { char a[10],b[10]; scanf("%s%s",a,b); int x,y; sscanf(a+1,"%d",&x); sscanf(b+1,"%d",&y); x--; y--; alg.Add(x,hsh[a[0]],y,hsh[b[0]]); } puts(alg.solve()?"GOOD":"BAD"); } return 0; }