#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

void OK(str& t){
	str s = "";
	for(auto c : t){
		if(c == 'R') s += c;
		else {
			if((s.size() > 0) && s.back() == 'S') s.pop_back();
			else s += c;
		}
	}
	t = s;
}

vector<int> Solve(int n, str T){
	int pw = 1;
	for(int i = 0; i < n; i++) pw = 3*pw;

	vector<int> res(pw, 0);
	if(n == 0){
		return res;
	}
	vector<int> rec(pw / 3);
	str T2;
	int nw;
	for(int bt = 0; bt < 3; bt ++){
		T2 = "";
		nw = bt;
		for(auto c : T){
			if(c == 'S'){
				T2 += c;
				if(nw != 0) nw = 3 - nw;
			} else {
				if(nw == 2) T2 += 'R';
				nw = (nw + 1) % 3;
			}
		}
		OK(T2);
		rec = Solve(n - 1, T2);
		for(int i = bt; i < pw; i += 3){
			res[i] = rec[i / 3] * 3 + nw;
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//str ts = "RSSSR";
	//OK(ts); debug(ts);
	int n;
	cin >> n;
	str T;
	cin >> T;
	vector<int> ans = Solve(n, T);
	for(auto x : ans) cout << x << ' ';
		cout << '\n';
	return 0;
}
