Example

Input

3 2
R1


Output

3 1 2
4 5 6
7 8 9
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
vvi id();
int num(int &);
vvi seq(int &);
vvi rep(int &);
vvi operation(int &);
string s;
int n, l;
int num(int &i) {
	int ret = 0;
	while (i < l&&isdigit(s[i])) {
		ret *= 10;
		ret += s[i] - '0';
		++i;
	}
	return ret;
}

vvi operation(int &i) {
	char c = s[i];
	++i;
	int a = num(i);
	vvi ret(n, vi(n));
	REP(k, n) {
		REP(j, n) {
			ret[k][j] = k*n + j;
		}
	}
	if (c == 'R') {
		REP(k, n - 1) {
			ret[a - 1][k + 1] = (a - 1)*n + k;
		}
		ret[a - 1][0] = (a - 1)*n + n - 1;
	}
	else if (c == 'L') {
		REP(k, n - 1) {
			ret[a - 1][k] = (a - 1)*n + k + 1;
		}
		ret[a - 1][n - 1] = (a - 1)*n;
	}
	else if (c == 'D') {
		REP(k, n - 1) {
			ret[k + 1][a - 1] = k*n + a - 1;
		}
		ret[0][a - 1] = (n-1)*n+a-1;
	}
	else if (c == 'U') {
		REP(k, n - 1) {
			ret[k][a - 1] = (k + 1)*n + a - 1;
		}
		ret[n - 1][a - 1] = a-1;
	}
	return ret;
}

vvi con(vvi b, vvi a) {
	vvi ret(n, vi(n));
	REP(i, n) {
		REP(j, n) {
			int c = a[i][j];
			int e = c%n, d = c / n;
			int f = b[d][e];
			ret[i][j] = f;
		}
	}
	return ret;
}

vvi rep(int &i) {
	++i;
	vvi ret = seq(i);
	++i;
	int a = num(i);
	int c = ceil(log2(a));
	vector<vvi> x(c+1);
	x[0] = ret;
	int j = 0;
	REP(k, c) {
		x[k + 1] = con(x[k], x[k]);
	}
	vvi ans = id();
	//cout << a <<" "<<c<< endl;
	REP(k, c+1) {
		if (a&(1 << k)) {
			ans = con(ans, x[k]);
			j += (1 << k);
		}
		
	}
	//cout << j << endl;
	return ans;
}
vvi seq(int &i) {
	if (i == l || s[i] == ')') {
		return id();
	}
	vvi a;
	if (s[i] == '(') {
		a = rep(i);
	}
	else {
		a = operation(i);
	}
	vvi ret = con(a, seq(i));
	return ret;
}
vvi id() {
	vvi a(n, vi(n));
	REP(i, n) {
		REP(j, n) {
			a[i][j] = i*n + j;
		}
	}
	return a;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n >> l;
	cin >> s;
	int i = 0;
	vvi a = seq(i);
	REP(k, n) {
		REP(j, n) {
			cout << a[k][j] + 1;
			if (j != n - 1)cout << " ";
			else cout << endl;
		}
	}

	return 0;
}