#include<iostream>
#include<string>
#include<math.h>
using namespace std ;
int main()
{
int T = 0 ;
cin>>T;
while(T--)
{
int M,i=0,ti,su=0;
string op;
cin >> M ;
while(M--)
{
cin >> op ;
if("IN"==op)
i++;
if("OUT"==op)
i--;
if("STAY"==op)
{
cin>>ti;
su+=ti*60/pow(20.0,i);
}
}
cout<<su<<endl;
}
}