// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std;

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto m = n - 1;

		auto c (string nx, string ny) (int [] [] a)
		{
			auto b = new int [] [] (n + m, n + m);
			foreach (x; -m..n)
			{
				foreach (y; -m..n)
				{
					auto z = -x - y;
					if (-n < z && z < n)
					{
						b[x + m][y + m] =
						    a[mixin (nx) + m]
						    [mixin (ny) + m];
					}
				}
			}
			return b;
		}

		alias r = c !("-y", "-z");
		alias t = c !("x", "z");

		auto a = new int [] [] (n + m, n + m);
		foreach (x; -m..n)
		{
			foreach (y; -m..n)
			{
				auto z = -x - y;
				if (-n < z && z < n)
				{
					readf !(" %s") (a[x + m][y + m]);
				}
			}
			readln;
		}

		auto cmd = readln.strip;
		int mult = +1;
		int rotate = 0;
		foreach (ref v; cmd)
		{
			switch (v)
			{
			case 'L': rotate = (rotate + 6 - mult) % 6; break;
			case 'R': rotate = (rotate + mult) % 6; break;
			case 'T': mult *= -1; break;
			default: assert (false);
			}
		}

		foreach (step; 0..rotate)
		{
			a = r (a);
		}
		if (mult < 0)
		{
			a = t (a);
		}

		foreach (x; -m..n)
		{
			writef !("%*s") (abs (x) * 2, "");
			foreach (y; -m..n)
			{
				auto z = -x - y;
				if (-n < z && z < n)
				{
					writef !("%*s") (4, a[x + m][y + m]);
				}
			}
			writeln;
		}
	}
}
