using System;
using System.IO;
using System.Collections.Generic;
public class Polygon
{
static List<int>[] cross;
static int x, y;
static UInt64 A, P;
static char orientation;
static int Max_index(int[] p)
{
int max = 0, idx = 0;
for (int i = 1; i < p.Length; i++)
{
if (p[i] >= max && cross[i].Count > 0) { max = p[i]; idx = i; }
}
return idx;
}
static int Min_index(int[] p)
{
int min = 6001, idx=0;
for (int i = 0; i < p.Length; i++)
{
if (p[i] <= min && cross[i].Count > 0) { min = p[i]; idx = i; }
}
return idx;
}
static void move(string s)
{
for (int i = 0; i < s.Length; i++)
{
if (s[i] == 'R')
{
if (orientation == 'U') orientation = 'R';
else if (orientation == 'R') orientation = 'D';
else if (orientation == 'D') orientation = 'L';
else orientation = 'U';
}
if (s[i] == 'L')
{
if (orientation == 'U') orientation = 'L';
else if (orientation == 'R') orientation = 'U';
else if (orientation == 'D') orientation = 'R';
else orientation = 'D';
}
if (s[i] == 'F')
{
if (orientation == 'U') y++;
else if (orientation == 'R') { cross[x].Add(y); x++; }
else if (orientation == 'D') y--;
else if (orientation == 'L') { x--; cross[x].Add(y); }
}
}
}
static void Main()
{
int L;
int[] max, min;
L = int.Parse(Console.ReadLine());
x = 3001; y = 3001; orientation = 'U';
cross=new List<int>[6002];
for (int i = 0; i < 6002; i++) cross[i] = new List<int>();
while (L > 0)
{
string[] p = Console.ReadLine().Split(' ');
for (int i = 0; i < p.Length - 1; i = i + 2)
{
for (int j = 0; j < int.Parse(p[i + 1]); j++) move(p[i]);
}
L -= (p.Length / 2);
}
A = 0;
for (int i = 0; i < 6002; i++)
{
cross[i].Sort();
for (int j = 0; j < cross[i].Count; j = j + 2)
{
A += (UInt64)(cross[i][j + 1] - cross[i][j]);
}
}
max = new int[6002]; min = new int[6002];
for (int i = 0; i < 6002; i++)
{
int len=cross[i].Count;
if (len > 0) max[i] = cross[i][len - 1];
else max[i] = 3001;
if (len > 0) min[i] = cross[i][0];
else min[i] = 3001;
}
int idx = Max_index(max);
int step = 0;
for (int i = 0; i <= idx; i++)
{
if (cross[i].Count > 0 && max[i] > step) step = max[i];
else if (cross[i].Count > 0 && max[i] < step) max[i] = step;
}
step = 0;
for (int i = 6001; i >= idx; i--)
{
if (cross[i].Count > 0 && max[i] > step) step = max[i];
else if (cross[i].Count > 0 && max[i] < step) max[i] = step;
}
idx = Min_index(min); step = 6001;
for (int i = 0; i <= idx; i++)
{
if (cross[i].Count > 0 && min[i] > step) min[i] = step;
else if (cross[i].Count > 0 && min[i] < step) step = min[i];
}
step = 6001;
for (int i = 6001; i >= idx; i--)
{
if (cross[i].Count > 0 && min[i] > step) min[i] = step;
else if (cross[i].Count > 0 && min[i] < step) step = min[i];
}
P = 0;
for (int i = 0; i < cross.Length; i++)
{
P += (UInt64)(max[i] - min[i]);
}
for (int i2 = 1; i2 < 2; i2++) {
for (int j2 = 1; j2 < 2; j2++) {
Console.WriteLine("{0} ",cross(0,0));
}
Console.WriteLine();
}
}
}