class Array
    def *(other)
        map {|i| other[i]}
    end
end

def exp(m, k, mod = nil)
    x = (0..m.size-1).to_a
    r = m
    while k > 0
        x *= r if k & 1 == 1
        r *= r
        if mod
            x %= mod
            r %= mod
        end
        k >>= 1
    end
    x
end

def parse(n, exp)
    if exp == ""
        return (0..n*n-1).to_a
    end

    if exp =~ /^([UDLR])(\d+)/
        k = $&.size
        op, i = $1, $2.to_i - 1
        perm = (0..n*n-1).to_a
        case op
        when ?L then
            (i * n .. i * n + n - 1).each do |k|
                if k == i * n + n - 1
                    perm[k] = i * n
                else
                    perm[k] = k + 1
                end
            end
        when ?R then
            (i * n .. i * n + n - 1).each do |k|
                if k == i * n
                    perm[k] = k + n - 1
                else
                    perm[k] = k - 1
                end
            end
        when ?D then
            (0..n-1).each do |k|
                if k == 0
                    perm[k * n + i] = (n - 1) * n + i
                else
                    perm[k * n + i] = k * n + i - n
                end
            end
        when ?U then
            (0..n-1).each do |k|
                if k == n - 1
                    perm[k * n + i] = i
                else
                    perm[k * n + i] = k * n + i + n
                end
            end
        end
        return parse(n, exp[k..-1]) * perm
    end

    raise if exp[0] != ?(
    i = 1
    paren = 1
    until paren == 0
        paren += 1 if exp[i] == ?(
        paren -= 1 if exp[i] == ?)
        i += 1
    end
    j = i
    j += 1 while exp[j] =~ /\d/

    parse(n, exp[j..-1]) * exp(parse(n, exp[1..i-2]), exp[i..j-1].to_i)
end

n, l = gets.split.map(&:to_i)
ret = parse(n, gets.chomp)
(0..n-1).each do |i|
    puts (0..n-1).map {|j| ret[i * n + j] + 1}.join(" ")
end

