#include<bits/stdc++.h>
using namespace std;
int T,i,n,m,flag,Max,x,y,t,e[255],f[110];
char c,a[110];
int read(){
int x=0,f=0;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='n') f=1;ch=getchar();}
while (ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
return x*f;
}
int Read(){
int x=0;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='n') return 0;ch=getchar();}
while (ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
return x;
}
int main(){
T=Read();
while (T--){
memset(e,0,sizeof(e));
memset(f,0,sizeof(f));
n=Read();m=read();flag=t=Max=0;
for (i=1;i<=n;i++){
cin>>c;flag|=(c=='E'&&!t);
if (c=='E'&&flag) continue;
if (c=='E') {e[a[t--]]=0;continue;}
cin>>c;x=Read();y=Read();flag|=e[c];
a[++t]=c;e[a[t]]=1;f[t]=-1e9;
if (flag) continue;
if (!x&&!y) f[t]=f[t-1];
if (x&&y&&x<=y) f[t]=f[t-1];
if (x&&!y) f[t]=f[t-1]+1,Max=max(Max,f[t]);
}
printf("%s\n",(flag||t)?"ERR":(Max==m?"Yes":"No"));
}
return 0;
}
直接使用快读,感觉根本不算大模拟,30min内AC了....