#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t;
int row,col;
char ch,c;
scanf("%d%c",&t,&ch);
while(t--)
{
scanf("%c%d%d%c",&ch,&row,&col,&c);
if(ch=='r')
{
printf("%d\n",(row<=col?row:col));
}
else if(ch=='k')
{
//knight alwsy attacks of the other color squares, so total non attacking
//knighta are = half of the area
//if total square is odd, i.e. dimensions are odd then total non attacking knights = half of the area +1
printf("%d\n",((row*col)+1)/2);
}
else if(ch=='K')
{
//for each 2x2 there is one King can be set
printf("%d\n",((row+1)/2)*((col+1)/2));
}
else if(ch=='Q')
{
printf("%d\n",(row<=col?row:col));
}
}
return 0;
}