local mfl, mce = math.floor, math.ceil
local bls, brs = bit.lshift, bit.rshift

local n = io.read("*n", "*l")
-- local n = 12
local tot = 3^n

local warp = {{}}
for i = 1, tot do
  local src = i - 1
  local tmp = src
  local dst = 0
  local mul = 1
  for j = 1, n do
    if src % 3 ~= 0 then
      dst = dst + mul * (3 - (src % 3))
    end
    mul = mul * 3
    src = mfl(src / 3)
  end
  warp[1][i] = dst + 1
end
local lim = 49
for iz = 2, lim + 1 do
  warp[iz] = {}
  for i = 1, tot do
    local src = i == tot and 1 or i + 1
    warp[iz][i] = warp[iz - 1][src]
  end
end
local cur = {}
for i = 1, tot do cur[i] = i end

local function walk(r)
  for i = 1, tot do
    local v = cur[i] + r
    while tot < v do v = v - tot end
    cur[i] = v
  end
end
-- print(os.clock())
-- os.exit()
local s = io.read()
s = s:gsub("SS", "")
local sn = #s

local rlen = 0
for i_s = 1, sn do
  if s:sub(i_s, i_s) == "S" then
    if lim < rlen then
      walk(rlen - lim)
      rlen = lim
    end
    for i = 1, tot do
      cur[i] = warp[rlen + 1][cur[i]]
    end
    rlen = 0
  else
    rlen = rlen + 1
  end
end
if rlen ~= 0 then
  walk(rlen)
end
for i = 1, tot do
  cur[i] = cur[i] - 1
end
print(table.concat(cur, " "))
