#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int FIVE = 243, SEVEN = 2187;
const int N = 200007;

int go[SEVEN][2];

int recon(vector<int> v) {
	int a = 0, deg = 1;
	for (int i = 0; i < 7; ++i) {
		a += deg*v[i];
		deg *= 3;
	}
	return a;
}

int go1(vector<int> a) {

	a[0]++;
	for (int i = 0; i < 7; ++i) {
		if (a[i]==3) {
			a[i] = 0;
			if (i < 6) a[i+1]++;
		}
		//cout << a[i] << " ";
	}


	return recon(a);

}

int go2(vector<int> a) {

	for (int i = 0; i < 7; ++i) {
		if (a[i]==1 || a[i]==2) {
			a[i] = 3-a[i];
		}
	}

	return recon(a);

}

int closest_zero[N];
int go_zero[N];

int cur_closest_zero[SEVEN];
int go_finish[SEVEN];

int spec[SEVEN];

string s;
vector<int> pref;

int get(int was, int l, int r) {
	int cnt = pref[r+1] - pref[l];
	//cout << was << " " << l << " " << r << endl;
	if (cnt % 2 == 0) return was;

	was = go[was][1];
	was %= FIVE;
	return was;

}

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	cin >> s;

	pref.push_back(0);
	for (int i = 0; i < s.size(); ++i) {
		pref.push_back(pref.back() + (s[i] == 'S'));
	}

	for (int i = 0; i < SEVEN; ++i) {

		vector<int> w;
		int Q = i;
		for (int j = 0; j < 7; ++j) {
			w.push_back(Q%3);
			Q /= 3;
		}

		int a = go1(w);
		int b = go2(w);

		//if (i==2) exit(0);

		go[i][0] = a, go[i][1] = b;

	}

	for (int i = 0; i < SEVEN; ++i) {
		go_finish[i] = i;
		cur_closest_zero[i] = 1;
	}

	for (int i = s.size() - 1; i >= 0; i--) {
		int code;
		if (s[i] == 'S') code = 1;
		else code = 0;

		for (int j = 0; j < SEVEN; ++j) {
			int be = go[j][code];
			if (be == 0 && s[i] == 'R') {
				spec[j] = 1;
			}
			else spec[j] = cur_closest_zero[be]+1;
		}

		for (int j = 0; j < SEVEN; ++j) cur_closest_zero[j] = spec[j];

		for (int j = 0; j < SEVEN; ++j) {
			int be = go[j][code];
			spec[j] = go_finish[be];
		}

		for (int j = 0; j < SEVEN; ++j) go_finish[j] = spec[j];
		closest_zero[i] = cur_closest_zero[0];
		go_zero[i] = go_finish[0];

		//cout << go_finish[0] << " " << go_finish[1] << " " << go_finish[2] << endl;

	}

	//cout << cur_closest_zero[SEVEN-1];
	//exit(0);

	int kek = 1;
	for (int i = 0; i < 12; ++i) kek *= 3;

	vector<int> ans(kek);

//cout << go[SEVEN-1][1] << endl;

	for (int i = 0; i < kek; ++i) {

		int sht = i%SEVEN, lng = i/SEVEN;
		int left = s.size();

		int C = cur_closest_zero[sht];
		if (C > left) {
			sht = go_finish[sht];
			left = 0;
			lng = get(lng, 0, s.size()-1);
		}

		else {
			sht = 0;
			left -= C;
			lng = get(lng, 0, C-1);
			if (i==SEVEN-1) {
				//cout << lng << endl;
				//exit(0);
			}
			lng = (go[lng][0]) % FIVE;
		}



		while (left) {
			int have = closest_zero[s.size() - left];

			if (have > left) {
				sht = go_zero[s.size() - left];
					
				lng = get(lng, s.size()-left, s.size()-1);
				left = 0;
			}
			else {
				sht = 0;
				lng = get(lng, s.size()-left, s.size()-(left-have)-1);
				left -= have;
				lng = (go[lng][0]) % FIVE;
			}
		}

		ans[i] = sht + SEVEN*lng;
	}
	//exit(0);

	int Q = 1;
	for (int i = 0; i < n; ++i) Q *= 3;

	for (int i = 0; i < Q; ++i) {
		cout << ans[i] % Q << " ";
	}











	

}


Measured memory_bytes: 8800