#include <bits/stdc++.h>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;
 
#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

#define MAX (1 << 20)

VInt V[MAX];
int A[MAX];

int f(int a)
{
    return a == 0 ? 0 : (a == 1 ? 2 : 1);
}

void solve(int test)
{
    int N;
    string T;
    cin >> N >> T;
    int i, j, k;
    int len = SIZE(T);
    VInt s(len + 1, 0);
    FOR(i, 0, len)
    {
        s[i + 1] = s[i];
        if(T[i] == 'S')
            s[i + 1] ^= 1;
        else
            V[0].push_back(i);
    }
    int offset = 0;
    int p3 = 1;
    FOR(i, 0, N)
    {
        FOR(j, 0, 3)
            FOR(k, 0, p3)
            {
                int a = j;
                int index = offset + (j + 1)*p3 + k;
                int prev = 0;
                for(int pos : V[offset + k])
                {
                    if(s[prev] != s[pos]) a = f(a);
                    ++a;
                    if(a == 3)
                    {
                        a = 0;
                        V[index].push_back(pos);
                    }
                    prev = pos;
                }
                if(s[len] != s[prev]) a = f(a);
                A[index] = a*p3 + A[offset + k];
            }

        offset += p3;
        p3 *= 3;
    }
    FOR(i, 0, p3) cout << A[offset + i] << ' ';
    cout << endl;
}

int main()
{
    int T, t;
    T = 1;
    FOR(t, 0, T) solve(t);
    return 0;
}
