Example

Input

3 2
R1


Output

3 1 2
4 5 6
7 8 9
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

typedef vector<int> vec;
typedef vector<vec> mat;
int n, l;
string s;
bool is_num(char t) {
	if ('0' <= t && t <= '9')return true;
	return false;
}
bool is_alf(char t) {
	if ('A' <= t && t <= 'Z')return true;
	return false;
}

int nex[100][100];
void mtmul(mat &A, mat &B) {
	rep(i, n) {
		rep(j, n) {
			int z = B[i][j];
			int x = z / n, y = z % n;
			nex[i][j] = A[x][y];
		}
	}
	rep(i, n) {
		rep(j, n) {
			A[i][j] = nex[i][j];
		}
	}
}
void repet(mat &A,int k) {
	mat ret(n);
	rep(i, n) {
		ret[i].resize(n);
		rep(j, n) {
			ret[i][j] = i * n + j;
		}
	}
	while (k) {
		if (k % 2) {
			mtmul(ret, A);
		}
		k >>= 1;
		mtmul(A, A);
	}
	A = ret;
}
void solve() {
	cin >> n >> l;
	cin >> s;
	mat E(n);
	rep(i, n) {
		E[i].resize(n);
		rep(j, n) {
			E[i][j] = i * n + j;
		}
	}
	stack<mat> st;
	mat cur = E;
	rep(i, l) {
		if (s[i] == '(') {
			st.push(cur); cur = E;
		}
		else if (is_alf(s[i])) {
			char memo = s[i];
			i++;
			int le = i;
			while (i + 1 < l&&is_num(s[i + 1]))i++;
			string t = s.substr(le, i - le + 1);
			int z = stoi(t) - 1;
			if (memo == 'L') {
				int u = cur[z][0];
				rep(j, n-1) {
					cur[z][j] = cur[z][j + 1];
				}
				cur[z][n - 1] = u;
			}
			else if (memo == 'R') {
				int u = cur[z][n - 1];
				for (int j = n - 1; j > 0; j--) {
					cur[z][j] = cur[z][j - 1];
				}
				cur[z][0] = u;
			}
			else if (memo == 'U') {
				int u = cur[0][z];
				rep(j, n - 1) {
					cur[j][z] = cur[j + 1][z];
				}
				cur[n - 1][z] = u;
			}
			else {
				int u = cur[n - 1][z];
				for (int j = n - 1; j > 0; j--) {
					cur[j][z] = cur[j - 1][z];
				}
				cur[0][z] = u;
			}
		}
		else if (s[i] == ')') {
			i++;
			int le = i;
			while (i + 1 < l&&is_num(s[i + 1]))i++;
			string t = s.substr(le, i - le + 1);
			int z = stoi(t);
			repet(cur,z);
			mat m = st.top(); st.pop();
			mtmul(m, cur);
			cur = m;
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (j > 0)cout << " ";
			cout << cur[i][j] + 1;
		}
		cout << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

