#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{ int j,t;
scanf("%d",&t);
for(j=0;j<t;j++) {
int k,i,truth=0,lie;
char str[90];
char a;
int b,n;
scanf("%d",&n);
scanf("%d\n",&k);
for(i=0;i<k;i++) {
scanf("\n%c %d %s",&a,&b,str);
int y=strcmp(str,"Yes");
int x=strcmp(str,"No");
if(a=='<') {
if(n<b&&y==0){
truth++;
}
else if(n>b&&x==0) {
truth++;
}
else if(n==b&&x==0) {
truth++;
}
}
else if(a=='>') {
if(n>b&&y==0){
truth++;
}
else if(n<b&&x==0) {
truth++;
}
else if(n==b&&x==0) {
truth++;
}
}
else if(a=='=') {
if(n==b&&y==0){
truth++;
}
else if(n<b&&x==0) {
truth++;
}
else if(n>b&&x==0) {
truth++;
}
}
}
printf(" %d\n",lie=k-truth);
}
return 0;
}