#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}

// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

const int MAXN = 1e6+10;


void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

string to_ter(int x, int k=-1) {
    string res;
    while(x) {
        res+='0'+x%3;
        x/=3;
    }
    if(k>=0) {
        while(res.size()<k) res+='0';
    }
    return res;
}
int to_int(const string & s) {
    int res=0;
    // rrep(i,s.size()-1,-1)
    //     res=res*3+(s[i]-'0');
    for(int i=s.size()-1;i>=0;i--)
        res=res*3+(s[i]-'0');
    // print(s,res);
    return res;
}
bool add(string & x, const string & y) {
    int n1=x.size(), n2=y.size(),carry=0;
    rep(i,0,n1) {
        if(i<n1) carry+=x[i]-'0';
        if(i<n2) carry+=y[i]-'0';
        x[i]=carry%3+'0';
        carry/=3;
    }
    return carry==0;
}

vi cal_inst(string & s) {
    int n=s.size();
    vi res(1);
    int i=0;
    while(i<n) {
        if(s[i]=='R') {
            res.back()++;
            i++;
        }
        else {
            int j=i;
            for(;j<n&&s[j]=='S';j++);
            if((j-i)%2) res.pb(0);
            i=j;
        }
    }
    if(s.back()=='S') res.pop_back();
    return res;
}

char rev(char c) {
    if(c>'0') return '0'+(3-(c-'0'));
    return c;
}
string rev(string s) {
    for(auto & c:s) c=rev(c);
    return s;
}

int len(string & s) {
    int res=s.size()-1;
    while(res>=0&&s[res]=='0') res--;
    return res+1;
}

int power[13]={};
int revmap[MAXN]={};
int tmpres[MAXN];
int rev(int x) {
    for(int flag=1;flag<power[12];flag*=3) {
        int tmp=x/flag%3;
        if(tmp==1) x+=flag;
        else if(tmp==2) x-=flag;
    }
    return x;
}

void cal(vi inst, int n, int tot) {
    // vi tmpres(tot,-1);
    fill(tmpres,tmpres+tot,-1);

    rep(i,0,tot) {
        if(tmpres[i]>=0) continue;

        int cur=i,ok=1;
        for(auto x:inst) {
            cur+=x;
            if(cur>=power[n]) {
                ok=0; 
                cur%=power[n];
            }
            cur=revmap[cur];
        }
        // if(i<=9) print(i,cur);
        tmpres[i]=cur;
        // assert(cur>=0);
        if(!ok) continue;
        int flag=1,tmp;
        for(;flag<=i||flag<=cur;flag*=3);

        if(inst.size()%2==0) {
            for(tmp=flag;tmp<power[n];tmp+=flag) {
                tmpres[tmp+i]=tmp+cur;
            }
        }
        else {
            for(tmp=flag;tmp<power[n];tmp+=flag) {
                tmpres[tmp+i]=revmap[tmp]+cur;
            }

        }
    }
    // print(1);
    // print(*max_element(all(res)),*min_element(all(res)));
    // return res;
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    string s;
    cin>>n;
    cin>>s;

    // n=12;
    // rep(i,0,1e5) s+="RS";

    power[0]=1;
    rep(i,1,13) power[i]=power[i-1]*3;
    int tot=power[n];
    rep(i,0,tot) revmap[i]=rev(i);
    printn(revmap,9);

    int ns=s.size();
    vi last(ns+1),lastn(ns+1);
    vi cur({0,1,2}),pre;

    last[0]=cur[2];
    rep(i,0,ns) {
        if(s[i]=='R') rotate(cur.begin(),cur.begin()+2,cur.end());
        // else for(auto & x:cur) x=revmap[x];
        else swap(cur[1],cur[2]);
        last[i+1]=cur[2];
    }
    lastn=last;
    print(cur,last);

    int flag=3;
    rep(iteration,2,n+1) {
        pre=cur;
        cur.insert(cur.end(),all(pre));
        cur.insert(cur.end(),all(pre));
        flag*=3;
        last=lastn;
        lastn[0]=flag-1;

        vvi tmp(flag/3,vi({0,1,2}));
        vi pre_upd(flag/3);
        int curt=0;
        print(tmp);
        rep(i,0,ns) {
            if(s[i]=='R') {
                int diff=(curt-pre_upd[last[i]])%2;
                if(diff) swap(tmp[last[i]][1],tmp[last[i]][2]);
                pre_upd[last[i]]=curt;
                rotate(tmp[last[i]].begin(),tmp[last[i]].begin()+2,tmp[last[i]].end());
            }
            else curt++;

            int diff=(curt-pre_upd[last[i+1]])%2;
            if(diff) swap(tmp[last[i+1]][1],tmp[last[i+1]][2]);
            pre_upd[last[i+1]]=curt;
            lastn[i+1]=last[i+1]+flag/3*tmp[last[i+1]][2];
            print(i,curt,pre_upd);
            print(last,lastn);
            print(tmp);
        }
        rep(i,0,flag/3) {
            int diff=(curt-pre_upd[i])%2;
            if(diff) swap(tmp[i][1],tmp[i][2]);
            pre_upd[i]=curt;
            // rotate(tmp[i].begin(),tmp[i].begin()+2,tmp[i].end());            
        }
        print(tmp);
        rep(i,0,flag/3) {
            cur[i]+=flag/3*tmp[pre[i]][0];
            cur[i+flag/3]+=flag/3*tmp[pre[i]][1];
            cur[i+flag/3*2]+=flag/3*tmp[pre[i]][2];
        }
    }
    print(lastn,cur);

    vi res(flag);
    rep(i,0,flag) res[cur[i]]=i;

    for(auto x:res) cout<<x<<' ';
    cout<<endl;
    


    return 0;
}




















Measured memory_bytes: 20156