#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <ll, pair <ll, ll>>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 6e5 + 10;
const ll maxm = 15;

ll n, m, k, t;

vector <ll> P[maxn];

ll W[maxm][maxn];

ll st3[maxn];

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    st3[0] = 1;
    for (q = 1; q < 20; q++) {
        st3[q] = st3[q - 1] * 3;
    }
    cin >> n;
    string s;
    cin >> s;
    P[0] = {0, 1, 2};
    W[0][0] = 2;
    for (q = 0; q < s.length(); q++) {
        vector <ll> C(3);
        for (w = 0; w < P[0].size(); w++) {
            C[P[0][w]] = w;
        }
        if (s[q] == 'S') {
            swap(P[0][C[1]], P[0][C[2]]);
        }
        else {
            for (w = 0; w < P[0].size(); w++) {
                P[0][w] = (P[0][w] + 1) % 3;
            }
        }
        for (w = 0; w < P[0].size(); w++) {
            C[P[0][w]] = w;
        }
        W[0][q + 1] = C[2];
    }
    // cout << "STARTING: " << endl;
    // for (q = 0; q < P[0].size(); q++) {
    //     cout << P[0][q] << endl;
    // }
    for (q = 1; q < n; q++) {
        vector <ll> D(st3[q + 1]);
        vector <ll> last(D.size());
        W[q][0] = D.size() - 1;
        // cout << W[q][0] << " MXI0" << endl;
        ll cnts = 0;
        for (w = 0; w < D.size(); w++) {
            D[w] = w / st3[q];
        }
        for (w = 0; w < s.length(); w++) {
            if (s[w] == 'R') {
                ll i = W[q - 1][w];
                for (ll j = i; j < st3[q + 1]; j += st3[q]) {
                    D[j] = (D[j] + 1) % 3;
                }
            }
            else {
                cnts++;
            }

            ll i = W[q - 1][w + 1];
            // cout << "I " << i << endl;
            ll mxi = i;
            for (ll j = i; j < st3[q + 1]; j += st3[q]) {
                if ((cnts - last[j]) % 2 == 1) {
                    if (D[j] != 0) {
                        D[j] = 3 - D[j];
                    }
                }
                last[j] = cnts;
                if (D[j] == 2) {
                    mxi = j;
                }
            }
            W[q][w + 1] = mxi;
            // cout << w + 1 << " " << mxi << " MXI" << endl;
            // cout << D.size() << endl;
            // for (e = 0; e < D.size(); e++) {
            //     if ((cnts - last[j]) % 2 == 1) {

            //     }
            //     // P[q][w] = P[q - 1][w % st3[q]] + D[w] * st3[q];
            //     cout << D[e] << " ";
            // }
            // cout << endl;
            // cout << endl;
        }
        P[q].resize(st3[q + 1]);
        for (w = 0; w < P[q].size(); w++) {
            if ((cnts - last[w]) % 2 == 1 && D[w] != 0) {
                D[w] = 3 - D[w];
            }
            P[q][w] = P[q - 1][w % st3[q]] + D[w] * st3[q];
            // cout << D[w] << " ";
        }
        // cout << endl;
    }
    for (q = 0; q < P[n - 1].size(); q++) {
        cout << P[n - 1][q] << " ";
    }
    return 0;
}


Measured memory_bytes: 51044