WA on #5 #10
#include<bits/stdc++.h>
using namespace std;
int T,L,len,O,sum,ans,FE,f[100005];
string str,x,y;
bool b,bol;
char ch,z;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
while(T--){
cin>>L>>str;
O=0;
if(str=="O(1)"){
O=0;
}else{
for(int i=0;i<str.length();i++){
if(str[i]>='0'&&str[i]<='9'){
O=O*10+str[i]-'0';
}
}
}
FE=sum=ans=0;
b=1;
bol=1;
memset(f,0,sizeof(f));
while(L--){
cin>>ch;
if(ch=='F'){
FE++;
cin>>z>>x>>y;
f[z]++;
if(f[z]>1){
b=0;
sum=0;
memset(f,0,sizeof(f));
}
if(x=="n"&&y=="n"){
continue;
}else if(x[0]>='0'&&x[0]<='9'){
if(y[0]>='0'&&y[0]<='9'){
if(x>y){
bol=0;
}
continue;
}else if(y=="n"&&bol){
sum++;
}
}else if(y[0]>='0'&&y[0]<='9'&&x=="n"){
bol=0;
}else{
continue;
}
}else{
FE--;
if(FE<0){
b=0;
sum=0;
memset(f,0,sizeof(f));
}
bol=1;
memset(f,0,sizeof(f));
ans=max(ans,sum);
sum=0;
}
}
if(!b){
cout<<"ERR\n";
}
if(FE>0&&b){
cout<<"ERR\n";
}
if(FE==0&&ans==O&&b){
cout<<"Yes\n";
}else if(FE==0&&b){
cout<<"No\n";
}
}
return 0;
}