Example

Input

3 2
R1


Output

3 1 2
4 5 6
7 8 9
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

struct Shift {
	ll n;
	vector<vector<ll>> mat;

	Shift(ll n) : n(n) {
		mat.assign(n, vector<ll>(n));
		REP(i, n) REP(j, n) mat[i][j] = i * n + j;
	}

	Shift(ll n, vector<vector<ll>> v) : n(n), mat(v) {
		REP(i, n) REP(j, n) mat[i][j] = v[i][j];
	}

	void left(ll m) {
		ll tmp = mat[m][0];
		REP(i, n - 1) mat[m][i] = mat[m][i + 1];
		mat[m][n - 1] = tmp;
		return;
	}

	void right(ll m) {
		ll tmp = mat[m][n - 1];
		for(ll i = n - 2; i >= 0; i--) mat[m][i + 1] = mat[m][i];
		mat[m][0] = tmp;
		return;
	}

	void up(ll m) {
		ll tmp = mat[0][m];
		REP(i, n - 1) mat[i][m] = mat[i + 1][m];
		mat[n - 1][m] = tmp;
		return;
	}

	void down(ll m) {
		ll tmp = mat[n - 1][m];
		for(ll i = n - 2; i >= 0; i--) mat[i + 1][m] = mat[i][m];
		mat[0][m] = tmp;
		return;
	}

	ll get(ll r, ll c) {
		return mat[r][c];
	}

	Shift operator * (Shift obj) {
		vector<vector<ll>> ret(n, vector<ll>(n, 0));
		REP(i, n) REP(j, n) {
			ll tmp1 = obj.get(i, j);
			ll tmp2 = mat[tmp1 / n][tmp1 % n];
			ret[i][j] = tmp2;
		}
		return Shift(n, ret);
	}
};

ll n, l;
string s;
ll pos = 0;

Shift operation();
Shift repetition();
Shift sequence();

ll number() {
	string numstr = "";
	while(pos < l && s[pos] >= '0' && s[pos] <= '9') {
		numstr += s[pos];
		pos++;
	}
	ll num = stol(numstr);
	return num;
}

Shift operation() {
	Shift ret(n);
	char shift = s[pos]; pos++;
	ll num = number();
	if(shift == 'L') ret.left(num - 1);
	if(shift == 'R') ret.right(num - 1);
	if(shift == 'U') ret.up(num - 1);
	if(shift == 'D') ret.down(num - 1);
	return ret;
}

Shift repetition() {
	Shift a(n);
	pos++; a = a * sequence(); pos++;
	ll num = number();
	Shift ret(n);
	while(num > 0) {
		if(num % 2) ret = ret * a;
		a = a * a;
		num /= 2;
	}
	return ret;
}

Shift sequence() {
	Shift ret(n);
	if(s[pos] == '(') ret = ret * repetition();
	else ret = ret * operation();
	if(pos == l || s[pos] == ')') return ret;
	else return ret * sequence();
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> l >> s;
	Shift ans = sequence();
	REP(i, n) REP(j, n) {
		cout << ans.get(i, j) + 1;
		if(j != n - 1) cout << " ";
		else cout << endl;
	}
 	return 0;
}

/* --------------------------------------- */


