#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

char T[200001];
vi com(vi ops) {
    int i;
    vi ops2;
    for (i = 0; i < ops.size(); i++) {
        if (ops[i] == 0) {
            if (!ops2.empty() && (ops2.back() == 0)) ops2.pop_back();
            else ops2.pb(0);
        }
        else {
            if (!ops2.empty() && (ops2.back() > 0)) ops2.back() += ops[i];
            else ops2.pb(ops[i]);
        }
    }
    return ops2;
}
vi getAns(int N,vi ops) {
    ops = com(ops);
    printArr(ops,ops.size());
    if (N == 1) {
        int i,j;
        vi v(3);
        v[0] = 0,v[1] = 1,v[2] = 2;
        for (i = 0; i < ops.size(); i++) {
            if (ops[i] == 0) {
                int a,b;
                for (j = 0; j < 3; j++) {
                    if (v[j] == 1) a = j;
                    if (v[j] == 2) b = j;
                }
                swap(v[a],v[b]);
            }
            else {
                for (j = 0; j < 3; j++) v[j] = (v[j]+ops[i]) % 3;
            }
        }
        return v;
    }

    int i,j;
    int p = 1;
    for (i = 0; i < N; i++) p *= 3;
    int x[3];
    x[0] = 0,x[1] = 1,x[2] = 2;
    vi ops2[3];
    for (i = 0; i < ops.size(); i++) {
        if (ops[i] == 0) {
            for (j = 0; j < 3; j++) {
                if (x[j] == 1) x[j] = 2;
                else if (x[j] == 2) x[j] = 1;
            }
            ops2[0].pb(0),ops2[1].pb(0),ops2[2].pb(0);
        }
        else {
            for (j = 0; j < 3; j++) {
                if (x[j]+ops[i] >= 3) ops2[j].pb((x[j]+ops[i])/3);
                x[j] = (x[j]+ops[i]) % 3;
            }
        }
    }
    vi vv[3];
    for (i = 0; i < 3; i++) {
        vv[i] = getAns(N-1,ops2[i]);
        printArr(vv[i],vv[i].size());
    }
    vi ans(p);
    for (i = 0; i < p; i++) ans[i] = 3*vv[i % 3][i/3]+x[i % 3];
    return ans;
}
int main() {
    int N;
    scanf("%d %s",&N,T);

    int i;
    vi ops;
    for (i = 0; T[i] != '\0'; i++) {
        if (T[i] == 'S') {
            if (!ops.empty() && (ops.back() == 0)) ops.pop_back();
            else ops.pb(0);
        }
        else {
            if (!ops.empty() && (ops.back() > 0)) ops.back()++;
            else ops.pb(1);
        }
    }
    vi v = getAns(N,ops);
    for (i = 0; i < v.size(); i++) printf("%d%c",v[i],(i == v.size()-1) ? '\n':' ');

    return 0;
}



Measured memory_bytes: 12020