#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

struct Node {
    int value;
    int lazy;
    Node *son[3];

    Node() {
        value = -1;
        lazy = 0;
        son[0] = son[1] = son[2] = nullptr;
    }
};

const int MAXVAL = 531441;

int answer[MAXVAL];

void refresh(Node *node) {
    if (node->lazy) {
        swap(node->son[1], node->son[2]);
        for (int b = 0; b < 3; b++)
            node->son[b]->lazy ^= 1;
        node->lazy = 0;
    }
}

void DFS(Node *node, int newValue, int power3) {
    if (node->value != -1) {
        answer[node->value] = newValue;
        return;
    }
    refresh(node);
    for (int b = 0; b < 3; b++)
        DFS(node->son[b], newValue + power3 * b, power3 * 3);
}

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("ultrapoligon.out");
    int n, limit = 1;
    cin >> n;
    for (int i = 1; i <= n; i++)
        limit *= 3;
    Node *root = new Node();
    for (int i = 0; i < limit; i++) {
        int x = i;
        Node *node = root;
        for (int j = 0; j < n; j++) {
            int b = x % 3;
            x /= 3;
            if (node->son[b] == nullptr) {
                node->son[b] = new Node();
            }
            node = node->son[b];
        }
        node->value = i;
    }
    string s;
    cin >> s;
    for (auto op : s) {
        if (op == 'S') {
            root->lazy ^= 1;
        }
        else {
            Node *node = root;
            for (int i = 0; i < n; i++) {
                refresh(node);
                Node *temp[3];
                for (int b = 0; b < 3; b++) {
                    temp[(b + 1) % 3] = node->son[b];
                }
                for (int b = 0; b < 3; b++) {
                    node->son[b] = temp[b];
                }
                node = node->son[0];
            }
        }
    }
    DFS(root, 0, 1);
    for (int i = 0; i < limit; i++)
        cout << answer[i] << " ";
    cout << "\n";
    timeEnd();
    //timeDuration();
    return 0;
}





Measured memory_bytes: 43800