#include<bits/stdc++.h>

using namespace std;

const int max3N = 550009;
int L, M, N = 10, p3[max3N], s[max3N], r[max3N], nxt[max3N], nxt2[max3N], sum[max3N], ans[max3N];
char sir[max3N];
vector < int > v[max3N];

int eval (int i, int v[], int l)
{
    for (int j=1; j<=l; j++)
        if (v[j] == 0) i = r[i];
        else i = s[i];
    return i;
}

const int N1 = 7, N2 = 7;
int v1[N1 + 5], v2[N2 + 5];
void back2 (int pos, int l1)
{
    if (pos > 2 && v2[pos - 1] == 1 && v2[pos - 2] == 1)
        return ;
    if (pos == 2 && v2[1] <= v1[1])
        return ;
    if (v2[pos - 1] != v1[l1])
    {
        int l2 = pos - 1;
        ///try to check whether v1[1..l1]=v2[1..l2]
        bool ok = 1;
        int cnt = 0, cntr[3] = {0, 0, 0};
        for (int i=0; i<p3[N]; i++)
        {
            if (eval (i, v1, l1) != eval (i, v2, l2))
                ok = 0;
            else cnt ++, cntr[i % 3] ++;
        }
        if (ok || cnt >= p3[N - 1])
        {
            printf ("%.3f: [%d, %d, %d] ", (double) cnt / p3[N], cntr[0], cntr[1], cntr[2]);
/*            bool ok2 = 1;
            for (int i=1; i<l1; i++)
                ok2 &= (v1[i] != 1 || v1[i + 1] != 1);
            if (!ok2)
            {
                ok2 = 1;
                for (int i=1; i<l2; i++)
                    ok2 &= (v2[i] != 1 || v2[i + 1] != 1);
            }
            if (ok2) printf ("WITHOUT: ");*/
            for (int i=1; i<=l1; i++)
                if (v1[i] == 0) printf ("R");
                else printf ("S");
            printf (" = ");
            for (int i=1; i<=l2; i++)
                if (v2[i] == 0) printf ("R");
                else printf ("S");
            printf ("\n");
        }
    }
    if (pos == N2)
        return ;
    for (int i=0; i<2; i++)
        v2[pos] = i, back2 (pos + 1, l1);
}

void back1 (int pos)
{
    if (pos > 2 && v1[pos - 1] == 1 && v1[pos - 2] == 1)
        return ;
    if (pos > 1)
        back2 (1, pos - 1);
    if (pos == N1)
        return ;
    for (int i=0; i<2; i++)
        v1[pos] = i, back1 (pos + 1);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &M);
N = M / 2;

p3[0] = 1;
for (int i=1; i<=M; i++)
    p3[i] = 3 * p3[i - 1];
for (int i=1; i<p3[M]; i++)
    if (i % 3 == 0) s[i] = s[i / 3] * 3;
    else
    if (i % 3 == 1) s[i] = s[i / 3] * 3 + 2;
    else s[i] = s[i / 3] * 3 + 1;
//for (int i=0; i<p3[N]; i++)
 //   r[i] = (i + 1) % p3[N];
scanf ("%s", sir + 1), L = strlen (sir + 1);
for (int j=0; j<p3[N]; j++)
    nxt[j] = j;
for (int i=1; i<=L; i++)
{
    if (sir[i] == 'S')
    {
        sum[i] = sum[i - 1] + 1;
        for (int j=0; j<p3[N]; j++)
            nxt[j] = s[nxt[j]];
        continue;
    }
    sum[i] = sum[i - 1];
    for (int j=0; j<p3[N]; j++)
    {
        if (nxt[j] == p3[N] - 1)
            v[j].push_back (i);
        nxt[j] = (nxt[j] + 1) % p3[N];
    }
}

for (int r = 0; r < p3[N]; r ++)
{
    for (int i=0; i<p3[M - N]; i++)
        nxt2[i] = i;
    int lst = 0, curr = 0;
    for (auto pos : v[r])
    {
        if (sum[pos] % 2 == sum[lst] % 2)
            curr ++;
        else
        {
            for (int i=0; i<p3[M - N]; i++)
                nxt2[i] = s[(nxt2[i] + curr) % p3[M - N]];
            curr = 1;
        }
        lst = pos;
    }
    for (int i=0; i<p3[M - N]; i++)
        nxt2[i] = (nxt2[i] + curr) % p3[M - N];
    if (sum[L] % 2 != sum[lst] % 2)
    {
        for (int i=0; i<p3[M - N]; i++)
            nxt2[i] = s[nxt2[i]];
    }
    for (int c=0; c<p3[M - N]; c++)
        ans[c * p3[N] + r] = nxt2[c] * p3[N] + nxt[r];
}
for (int i=0; i<p3[M]; i++)
    printf ("%d%c", ans[i], " \n"[i == p3[M] - 1]);
//back1 (1), v2[0] = -1;
/*RRSRSSSSR
int v[] = {-1, 0, 0, 1, 0, 1, 1, 1, 1, 0};
for (int i=0; i<p3[N]; i++)
    printf ("%d%c", eval (i, v, 9), " \n"[i == p3[N] - 1]);*/
/*int cnt = 0;
for (int i=0; i<p3[N]; i++)
    cnt += (r[r[s[r[i]]]] == s[r[r[i]]]);
printf ("%d\nout of\n%d\n", cnt, p3[N]);*/
return 0;
}


Measured memory_bytes: 23552