#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC target("avx2")  //Enable AVX


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 17;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

/*

pair<int, int> solve1(ll l, ll r)
{
    int answer = 0;
    while (l>= answer+1 || r>=answer+1)
    {
        answer++;
        if (l>=r) l-=answer; else r-=answer;
    }
    //cout<<"Case #:"<<answer<<' '<<l<<' '<<r<<endl;
    return mp(l, r);
}*/

vector<int> degs(15);

pair<string, int> produce(int dig, pair<string, int> a, int depth)
{;
    vector<char> op;
    for (auto c: a.first)
    {
        if (c=='S')
        {
            if (dig==1) dig = 2;
            else if (dig==2) dig = 1;
            if (op.size()>0 && op.back()=='S') op.pop_back();
            else op.push_back('S');
        }
        else
        {
            if (dig==2)
            {
                dig = 0; op.push_back('R');
            }
            else dig++;
        }
    }
    string res;
    for (auto c: op) res+=c;
    return mp(res, dig*degs[depth] + a.second);
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    degs[0] = 1;
    for (int i = 1; i<15; i++) degs[i] = degs[i-1]*3;

    int N; string t;
    cin>>N>>t;

    vector<char> T;
    for (auto c: t)
    {
        if (c=='S' && T.size()>0 && T.back()=='S') T.pop_back();
        else T.push_back(c);
    }

    string s;
    for (auto c: T) s+=c;

    vector<pair<string, int>> a = {mp(s, 0)};

    for (int i = 0; i<N; i++)
    {
        vector<pair<string, int>> b(degs[i+1]);
        for (int j = 0; j<degs[i]; j++)
        {
            for (int dig = 0; dig<3; dig++)
            {
                b[dig*degs[i] + j] = produce(dig, a[j], i);
            }
        }
        a = b;
    }

    for (int i = 0; i<degs[N]; i++) cout<<a[i].second<<' ';



}



Measured memory_bytes: 53472