#include <bits/stdc++.h>

const int MAX_NODES = int(2e6) + 10;

struct Trie {
	int val;
	bool rev;
	std::vector<std::pair<int, int> > go;
	void push() {
		if (!rev || go.empty())
			return;
		rev = 0;
		int p1, p2;
		for (int i = 0; i < 3; ++i) {
			if (go[i].first == 1)
				p1 = i;
		}
		for (int i = 0; i < 3; ++i) {
			if (go[i].first == 2)
				p2 = i;
		}
		// std::cout<<p1<<" "<<p2<<std::endl;
		std::swap(go[p1].first, go[p2].first);
	}
	void debug(int id) {
		std::cout << id << ": " << std::endl;
		for (int i = 0; i < 3; ++i)
			std::cout << go[i].first << " " << go[i].second << std::endl;
	}
} trie[MAX_NODES];

int n, base, trie_tot = 1;
int pow_3[20], ans[MAX_NODES];

void build(int cur, int dep, int val) {
	if (dep == base + 1) {
		trie[cur].val = val;
		return;
	}
	for (int i = 0; i < 3; ++i) {
		trie[cur].go.emplace_back(i, ++trie_tot);
		build(trie_tot, dep + 1, val + pow_3[dep - 1] * i);
	}
	// trie[cur].debug(cur);
}

void modify(int cur) {
	// std::cout<<cur<<std::endl;
	if (trie[cur].go.empty())
		return;
	// trie[cur].debug(cur);
	if (trie[cur].rev) {
		trie[cur].push();
		for (int i = 0; i < 3; ++i) {
			// std::cout<<i<<std::endl;
			trie[trie[cur].go[i].second].rev ^= 1;
		}
	}
	for (int i = 0; i < 3; ++i) {
		(++trie[cur].go[i].first) %= 3;
		if (!trie[cur].go[i].first)
			modify(trie[cur].go[i].second);
	}
}

void dfs(int cur, int p, int dep) {
	if (trie[cur].go.empty()) {
		ans[trie[cur].val] = p;
	} else {
		if (trie[cur].rev) {
			trie[cur].push();
			for (int i = 0; i < 3; ++i)
				trie[trie[cur].go[i].second].rev ^= 1;
		}
		for (int i = 0; i < 3; ++i) 
			dfs(trie[cur].go[i].second, p + pow_3[dep - 1] * trie[cur].go[i].first, dep + 1);
	}
}

int main() {
	scanf("%d", &base);
	pow_3[0] = 1;
	for (int i = 1; i <= base; ++i) {
		pow_3[i] = pow_3[i - 1] * 3;
	}
	n = pow_3[base];
	build(1, 1, 0);
	std::string opt;
	std::cin >> opt;
	for (auto c : opt) {
		// std::cout<<c<< "\n";
		if (c == 'S')
			trie[1].rev ^= 1;
		else
			modify(1);
	}
	dfs(1, 0, 1);
	for (int i = 0; i < n; ++i) {
		printf("%d ", ans[i]);
	}
}