Example

Input

3 2
R1


Output

3 1 2
4 5 6
7 8 9
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,l,t=0;
string s;
int number(){
	int q=0;
	while(t<s.size()&&isdigit(s[t])){
		q*=10;
		q+=s[t]-'0';
		t++;
	}
	return q;
}
vvi f(){
	vvi w(n,vi(n));
	rep(i,n)rep(j,n)w[i][j]=i*n+j;
	while(t<s.size()){
		if(s[t]=='('){
			t++;
			vvi ne=f();
			t++;
			int co=number();
			while(co){
				if(co%2){
					vvi NE(n,vi(n));
					rep(i,n)rep(j,n)NE[i][j]=w[ne[i][j]/n][ne[i][j]%n];
					w=NE;
				}
				vvi NE(n,vi(n));
				rep(i,n)rep(j,n)NE[i][j]=ne[ne[i][j]/n][ne[i][j]%n];
				ne=NE;
				co/=2;
			}
		}else if(s[t]==')')break;
		else{
			char c=s[t];
			t++;
			int co=number()-1;
			int tmp;
			if(c=='U'){
				tmp=w[0][co];
				rep(i,n-1)w[i][co]=w[i+1][co];
				w[n-1][co]=tmp;
			}
			if(c=='D'){
				tmp=w[n-1][co];
				rep(i,n-1)w[n-1-i][co]=w[n-2-i][co];
				w[0][co]=tmp;
			}
			if(c=='L'){
				tmp=w[co][0];
				rep(i,n-1)w[co][i]=w[co][i+1];
				w[co][n-1]=tmp;
			}
			if(c=='R'){
				tmp=w[co][n-1];
				rep(i,n-1)w[co][n-1-i]=w[co][n-2-i];
				w[co][0]=tmp;
			}
		}
	}
	return w;
}
int main(){
	cin>>n>>l>>s;
	t=0;
	vvi out=f();
	rep(i,n)rep(j,n)cout<<out[i][j]+1<<" \n"[j==n-1];
}









