# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int L = 15, N = 200100;
vector <int> mp[L];
int n, ans[1000010], mul[L];
char st[N];
void dfs(int k, int fm, int to){
	if (k == n){
		ans[fm] = to;
		return;
	}
	for (int i = 0; i < 3; i++){
		mp[k + 1].clear();
		int x = i;
		for (unsigned j = 0; j < mp[k].size(); j++){
			if (mp[k][j] == 0){
				x = x + 1;
				if (x % 3 == 0){
					x = 0;
					mp[k + 1].push_back(0);
				}
			}
			else {
				x = x * 2 % 3;
				if (mp[k + 1].size() > 0 && mp[k + 1][mp[k + 1].size() - 1] == 1)
					mp[k + 1].pop_back();
					else mp[k + 1].push_back(1);
			}
		}
		dfs(k + 1, fm + i * mul[k], to + x * mul[k]);
	}
}
int main(){
	read(n);
	scanf("\n%s", st + 1);
	int l = strlen(st + 1); 
	for (int i = 1; i <= l; i++){
		int t;
		if (st[i] == 'R') t = 0; else t = 1;
		if (t == 1 && mp[0].size() > 0 && mp[0][mp[0].size() - 1] == 1){
			mp[0].pop_back();
			continue;
		}
		mp[0].push_back(t);
	}
	mul[0] = 1;
	for (int i = 1; i <= n; i++) mul[i] = mul[i - 1] * 3;
	dfs(0, 0, 0);
	for (int i = 0; i < mul[n]; i++)
		printf("%d%c", ans[i], (i == mul[n] - 1) ? '\n' : ' ');
	return 0;
}

