#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N;
int Sanba[1 << 20];
int Ret[1 << 20];
string T;
vector<int> C[1 << 20];

int power[1 << 20];
int powerru[1 << 20];
int Answer[1 << 20];

void init() {
	power[0] = 1; powerru[0] = 1;
	for (int i = 1; i <= 18; i++) power[i] = 3 * power[i - 1];
	for (int i = 1; i <= 18; i++) powerru[i] = powerru[i - 1] + power[i];
}

int main() {
	cin >> N >> T; init();
	for (int i = 0; i < T.size(); i++) {
		Sanba[i + 1] = Sanba[i];
		if (T[i] == 'S') Sanba[i + 1] += 1;
	}

	// 最初の計算
	for (int i = 1; i <= 3; i++) {
		int cur = (i - 1);
		for (int j = 0; j < T.size(); j++) {
			if (T[j] == 'S') {
				if (cur == 1) cur = 2;
				else if (cur == 2) cur = 1;
			}
			if (T[j] == 'R') {
				cur += 1;
				if (cur == 3) { C[i].push_back(j); cur = 0; }
			}
		}
		Ret[i] = cur;
	}

	// 計算
	for (int i = 1; i < powerru[N - 1]; i++) {
		for (int j = 0; j < 3; j++) {
			int nex = i * 3 + (j + 1);
			int cx = -1, cur = j;
			for (int k : C[i]) {
				int steps = Sanba[k + 1] - Sanba[cx + 1];
				if ((steps & 1) == 1) {
					if (cur == 1) cur = 2;
					else if (cur == 2) cur = 1;
				}
				cur += 1;
				if (cur == 3) { C[nex].push_back(k); cur = 0; }
				cx = k;
			}
			int steps2 = Sanba[T.size()] - Sanba[cx + 1];
			if ((steps2 & 1) == 1) {
				if (cur == 1) cur = 2;
				else if (cur == 2) cur = 1;
			}
			Ret[nex] = cur;
		}
	}

	// 答えを出力
	for (int i = powerru[N - 1]; i < powerru[N]; i++) {
		int cx = i, ans = 0, pow = N, rem = 0;
		while (cx >= 1) {
			pow -= 1;
			ans += power[pow] * Ret[cx];
			rem += power[pow] * ((cx - 1) % 3);
			cx = (cx - 1) / 3;
		}
		Answer[rem] = ans;
	}

	for (int i = 0; i < power[N]; i++) {
		if (i) printf(" "); printf("%d", Answer[i]);
	}
	printf("\n");
	return 0;
}