Example

Input

3 2
R1


Output

3 1 2
4 5 6
7 8 9
#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

VL seq(int&,string&);
VL rep(int&,string&);
VL op(int&,string&);
LL number(int&,string&);

int N;
VL comp(const VL& f1, const VL& f2){
  VL res(N*N);
  REP(i,N*N) res[i] = f2[f1[i]];
  return res;
}

VL seq(int& i, string& s){
  VL res(N*N);
  REP(i,N*N) res[i] = i;

  while(i < SZ(s)){
	VL tmp;
	if(s[i] == '('){
	  tmp = rep(i, s);
	}
	else if(string("UDLR").find(s[i]) != string::npos){
	  tmp = op(i, s);
	}
	else{
	  break;
	}
	res = comp(res, tmp);
  }
  return res;
}
VL rep(int& i, string& s){
  ++i;
  VL tmp = seq(i, s);
  ++i;
  LL n = number(i, s);

  VL res(N*N);
  REP(i,N*N) res[i] = i;
  while(n>0){
	if(n&1)
	  res = comp(res, tmp);
	tmp = comp(tmp, tmp);
	n >>= 1;
  }

  return res;
}
VL op(int& i, string& s){
  char c = s[i];
  ++i;
  LL n = number(i, s);
  --n;

  VL res(N*N);
  REP(i,N*N) res[i] = i;
  switch(c){
  case 'R':
	REP(i,N-1) res[n*N+i] = n*N+i+1;
	res[n*N+N-1] = n*N;
	break;
  case 'L':
	REP(i,N-1) res[n*N+i+1] = n*N+i;
	res[n*N] = n*N + N-1;
	break;
  case 'U':
	REP(i,N-1) res[(i+1)*N+n] = i*N+n;
	res[n] = (N-1)*N + n;
	break;
  case 'D':
	REP(i,N-1) res[i*N+n] = (i+1)*N+n;
	res[(N-1)*N+n] = n;
	break;
  }

  return res;
}
LL number(int& i, string& s){
  LL n = 0;
  while(i < SZ(s) && '0' <= s[i] && s[i] <= '9'){
	n = n*10 + s[i] - '0';
	++i;
  }
  return n;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int L;
  cin >> N >> L;
  string S;
  cin >> S;
  int i = 0;
  VL rot = seq(i, S);
  VVI ans(N, VI(N));
  REP(i,N*N){
	int tx = rot[i] % N, ty = rot[i] / N;
	ans[ty][tx] = i+1;
  }

  REP(y,N){
	REP(x,N) cout << (x?" ":"") << ans[y][x];
	cout << endl;
  }
  
  return 0;
}