#include "random.h"
#include <cassert>
#include <cstring>

using namespace std;          

int n,cnt;
char s[1000][1000];
char t[1000][1000];

int main(int argc,char** argv){
	
	assert(argc >= 2);
	assert(strlen(argv[1]));
	assert(scanf("%d",&n)==1);
	for (int i = 0; i < n; i++){
		assert(scanf("%s",s[i]) == 1);
		assert((int)strlen(s[i]) == n);
	}

	if (argv[1][0] == 'H' || argv[1][0] == 'B'){
		for (int j = 0; j < n; j++)
			for (int i = 0; i < n-i-1; i++)
				swap(s[i][j], s[n-i-1][j]);
	}

	if (argv[1][0] == 'V' || argv[1][0] == 'B'){
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n-j-1; j++)        
				swap(s[i][j], s[i][n-j-1]);
	}

	if (argv[1][0] == 'R'){
		assert(strlen(argv[1]) > 1);
		for (int tmp = '0'; tmp < argv[1][1]; tmp++){
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					t[n-j-1][i] = s[i][j];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					s[i][j] = t[i][j];
		}
	}

                                    	
	printf("%d\n",n);
	for (int i = 0; i < n; i++)
		printf("%s\n",s[i]);
	return 0;
}
