/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class TaskC {
 public:
  int n;
  string t;
  int size;
  vector<int> p3;
  vector<int> flip;
  vector<bool> inverted;
  vector<vector<pair<int, int>>> dest;

  pair<int, int> getJump(int when, int tail0, int before) {
    if (when == t.size()) return {when, before * p3[tail0]};
    int key = tail0 * 3 + before;
    if (dest[when][key].first >= 0) return dest[when][key];
    if (before == 0) {
      if (tail0 == 0) {
        int time = when;
        while (time < t.size() && t[time] == 'S') ++time;
        if (time == t.size()) {
          dest[when][key] = {time, 0};
          return dest[when][key];
        } else {
          dest[when][key] = {time + 1, -1};
          return dest[when][key];
        }
      } else {
        auto change = getJump(when, tail0 - 1, 0);
        if (change.second >= 0) {
          assert(change.first == t.size());
          dest[when][key] = change;
          return change;
        }
        int state = inverted[change.first] ? 2 : 1;
        dest[when][key] = getJump(change.first, tail0 - 1, state);
        if (tail0 == n && dest[when][key].second < 0) {
          dest[when][key] = getJump(dest[when][key].first, tail0, 0);
        }
        return dest[when][key];
      }
    } else {
      auto change = getJump(when, tail0, 0);
      if (change.second >= 0) {
        assert(change.first == t.size());
        dest[when][key] = change;
        dest[when][key].second += before * p3[tail0];
        return dest[when][key];
      }
      if (inverted[change.first]) before = 3 - before;
      ++before;
      if (before == 3) {
        dest[when][key] = change;
        return change;
      } else {
        if (inverted[change.first]) before = 3 - before;
        dest[when][key] = getJump(change.first, tail0, before);
        return dest[when][key];
      }
    }
  }

  int get(int pos, int when) {
    while (when < t.size()) {
      int rem = pos;
      int tail0 = 0;
      while (rem % 3 == 0 && tail0 < n) {
        ++tail0;
        rem /= 3;
      }
      pos -= (rem % 3) * p3[tail0];
      pair<int, int> jump = getJump(when, tail0, rem % 3);
      when = jump.first;
      if (jump.second >= 0) {
        pos += jump.second;
      } else {
        if (inverted[when]) pos = flip[pos];
        pos += p3[tail0 + 1];
        if (pos >= size) pos -= size;
        if (inverted[when]) pos = flip[pos];
      }
    }
    return pos;
  }

  void solveOne(istream &in, ostream &out) {
    in >> n;
    in >> t;
    size = 1;
    p3 = vector<int>(n + 1);
    p3[0] = 1;
    for (int i = 0; i < n; ++i) {
      size = size * 3;
      p3[i + 1] = size;
    }
    inverted = vector<bool>(t.size() + 1);
    for (int i = 0; i < t.size(); ++i) {
      if (t[i] == 'S') inverted[i + 1] = !inverted[i]; else inverted[i + 1] = inverted[i];
    }
    flip = vector<int>(size);
    for (int i = 0; i < size; ++i) {
      flip[i] = flip[i / 3] * 3;
      int r = i % 3;
      if (r == 1) flip[i] += 2; else if (r == 2) ++flip[i];
    }
    dest = vector<vector<pair<int, int>>>(t.size(), vector<pair<int, int>>((n + 1) * 3, pair<int, int>(-1, -1)));
    for (int i = 0; i < size; ++i) {
      int res = get(i, 0);
      if (inverted[t.size()]) res = flip[res];
      out << res << " ";
    }
    out << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskC solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 79808