#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
char s[10];
int t, step;
scanf("%d", &t);
while(t--) {
int point[6] = {0, 0, 0, 0, 0, 0};
int dir = 0, head = 2, left = 4, n;
scanf("%d", &n);
getchar();
while(n--) {
scanf("%s%d", s, &step);
if(s[0] == ‘f‘) {
point[dir] += step;
}
else if(s[0] == ‘b‘) {
left = (left + 3) % 6;
dir = (dir + 3) % 6;
point[dir] += step;
}
else if(s[0] == ‘l‘) {
int t = dir;
dir = left;
left = (t + 3) % 6;
point[dir] += step;
}
else if(s[0] == ‘r‘) {
int t = dir;
dir = (left + 3) % 6;
left = t;
point[dir] += step;
}
else if(s[0] == ‘u‘) {
int t = dir;
dir = head;
head = (t + 3) % 6;
point[dir] += step;
}
else if(s[0] == ‘d‘){
int t = dir;
dir = (head + 3) % 6;
head = t;
point[dir] += step;
}
}
printf("%d %d %d %d\n", point[0] - point[3], point[1] - point[4], point[2] - point[5], dir);
}
return 0;
}