#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<vector <int> > turn(vector< vector<int> > &a, int k)
{
	vector< vector<int> > b(k);
	reverse(a.begin(), a.end());

	for (int i = 0; i < k; i++)
	{
		b[i].push_back(a[i].back());
		a[i].pop_back();
		for (int j = i - 1; j > -1; j--)
		{
			b[i].push_back(a[j].back());
			a[j].pop_back();
			b[i].push_back(a[j].back());
			a[j].pop_back();
		}
	}
	return b;
}

int main()
{
	freopen("triangle.in", "r", stdin);
	freopen("triangle.out", "w", stdout);
	int n;
	cin >> n;
	vector< vector<int> > a(n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 2 * i + 1; j++)
		{
			int x;
			cin >> x;
			a[i].push_back(x);
		}
	string s;
    cin >> s;
    a = turn(a, n);
    if (s == "clockwise")
        a = turn(a, n);
	
    for (int i = 0; i < n; i++)
		for (int j = 0; j < 2 * i + 1; j++)
			cout << a[i][j] << ((j != 2 * i) ? " " : "\n");
	cout << "\n";
}


