import java.io.*;

public class triangle_nn_java {

	static void solve() throws Exception {
		int n = Integer.parseInt(br.readLine());
		int[][] a = new int[n][];
		for (int i = 0, j = 1; i < n; i++, j += 2) {
			String[] t = br.readLine().split(" ");
			if (t.length != j) {
				throw new AssertionError();
			}
			a[i] = new int[j];
			for (int k = 0; k < j; k++) {
				a[i][k] = Integer.parseInt(t[k]);
			}
		}
		String s = br.readLine();
		assert s.equals("clockwise") || s.equals("counterclockwise");
		a = rotate(a);
		if (s.equals("clockwise")) {
			a = rotate(a);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < a[i].length; j++) {
				if (j > 0) {
					out.print(' ');
				}
				out.print(a[i][j]);
			}
			out.println();
		}
	}

	static int[][] rotate(int[][] a) {
		int n = a.length;
		int[][] ret = new int[n][];
		for (int i = 0, current = (n - 1) * 2; i < n; i++, current -= 2) {
			ret[i] = new int[i * 2 + 1];
			ret[i][0] = a[n - i - 1][current];
			int count = 1;
			for (int j = n - i; j < n; j++) {
				ret[i][count++] = a[j][current + 1];
				ret[i][count++] = a[j][current];
			}
		}
		return ret;
	}

	static BufferedReader br;
	static PrintWriter out;

	public static void main(String[] args) {
		try {
			File file = new File("triangle.in");
			InputStream input = System.in;
			OutputStream output = System.out;
			if (file.canRead()) {
				input = (new FileInputStream(file));
				output = (new PrintStream("triangle.out"));
			}
			br = new BufferedReader(new InputStreamReader(input));
			out = new PrintWriter(output);
			solve();
			out.close();
			br.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}