#include<bits/stdc++.h>
using namespace std;
int n;
stack<char> s1,s2;
stack<int> s3,s4;
stack<string> s5,s6;
void init(){
while(!s1.empty())s1.pop();
while(!s2.empty())s2.pop();
while(!s3.empty())s3.pop();
while(!s4.empty())s4.pop();
while(!s5.empty())s5.pop();
while(!s6.empty())s6.pop();
}
int main(){
int t;
cin >> t;
while(t--){
init();
cin >> n;
string s;
cin >> s;
char a;
string b,c,d;
bool flag1 = 1,flag2 = 0;;
int cnt = 0,ans = -10;;
while(n--){
cin >> a;
if(a == 'F'){
int m = 0;
cin >> b >> c >> d;
if(c == d)m = 0;
else if(d == "n" && c != "n")m = 1;
else if(c > d)flag2 = 1;
else if(c =="n" && d[0] >='0' && d[0] <= '9')flag2 = 1;
if(flag2)m = 0;
s3.push(m);
if(!flag2){
s1.push('F');
}
else s1.push('P');
while(!s5.empty()){
string h;
h = s5.top();
s5.pop();
s6.push(h);
if(h == b){
flag1 = 0;
}
}
s6.push(b);
while(!s6.empty()){
string h;
h = s6.top();
s6.pop();
s5.push(h);
}
}
else if(a == 'E'){
while(!s3.empty()){
int k = s3.top();
s3.pop();
cnt += k;
s4.push(k);
}
while(!s4.empty()){
int k = s4.top();
s4.pop();
s3.push(k);
}
ans = max(ans,cnt);
cnt = 0;
if(!s1.empty()){
s3.pop();
s1.pop();
char w;
if(!s1.empty())w = s1.top();
if(w == 'F')flag2 = 0;
s5.pop();
}
else {
while(!s1.empty()){
s1.pop();
s3.pop();
s5.pop();
}
flag1 = 0;
}
}
}
while(!s1.empty()){
s1.pop();
s3.pop();
s5.pop();
flag1 = 0;
}
if(!flag1){
printf("ERR\n");
continue;
}
int k = 0;
bool flag = 0;
if(s.size() == 4){
if(ans == 0)flag = 1;
}
else{
for(int i = 0; i < s.size(); i++){
if(s[i] >= '0' && s[i] <= '9'){
int l = s[i] - '0';
k *= 10;
k += l;
}
}
if(k == ans)flag = 1;
}
if(!flag){
printf("No\n");
}
else printf("Yes\n");
}
}