#pragma comment(linker, "/STACK:512000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
  string s = FILENAME;
//    assert(!s.empty());
  freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/cryptozoology/output.txt", "w", stdout);
#else
//    freopen(FILENAME ".in", "r", stdin);
//    freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0)
  {
    if (rl.rlim_cur < kStackSize)
    {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0)
      {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
      //cout << "Case #" << testNum++ << ": ";
      solve(true);
  }
  cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cout.flush();
  auto end = clock();

  usleep(10000);
  print_stats(end - start);
  usleep(10000);
#endif

    return 0;
}

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {
}

//#define int li
//const int mod = 1000000007;

struct Data {
  vector<int> vals;
  string s;
  void append(char c) {
    if (!s.empty() && s.back() == 'S' && c == 'S') {
      s.pop_back();
    } else {
      s += c;
    }
  }
  void swap(Data& ot) {
    vals.swap(ot.vals);
    s.swap(ot.s);
  }
};

void solve(__attribute__((unused)) bool read) {
  int n;
  cin >> n;
  string t;
  cin >> t;
  string s;
  for (char c : t) {
    if (c == 'S' && !s.empty() && s.back() == 'S') {
      s.pop_back();
      continue;
    }
    s += c;
  }
  int step = 1;
  for (int i = 0; i < n; ++i) {
    step *= 3;
  }
  vector<vector<int>> repr(step, vector<int>(n));
  for (int val = 0; val < step; ++val) {
    int m = val;
    for (int i = 0; i < n; ++i) {
      repr[val][i] = m % 3;
      m /= 3;
    }
  }
  vector<int> init(step);
  iota(all(init), 0);
  Data initial_data = {init, s};
  vector<vector<int>> res(step, vector<int>(n));
  vector<Data> cur_datas = {initial_data};
  vector<Data> next_datas;
  for (int w = 0; w < n; ++w) {
    next_datas.clear();
    for (auto& data : cur_datas) {
      vector<Data> new_datas(3);
      for (int i = 0; i < data.vals.size(); ++i) {
        new_datas[i % 3].vals.push_back(data.vals[i]);
      }
      for (char c : data.s) {
        if (c == 'R') {
          new_datas[2].append('R');
          new_datas[2].swap(new_datas[0]);
          new_datas[2].swap(new_datas[1]);
        } else {
          for (int i = 0; i < 3; ++i) {
            new_datas[i].append('S');
          }
          new_datas[1].swap(new_datas[2]);
        }
      }
      for (int i = 0; i < 3; ++i) {
        for (int x : new_datas[i].vals) {
          res[x][w] = i;
        }
        next_datas.push_back(new_datas[i]);
      }
    }
    next_datas.swap(cur_datas);
  }
  for (int i = 0; i < step; ++i) {
    int ans = 0;
    for (int j = n - 1; j >= 0; --j) {
      ans = ans * 3 + res[i][j];
    }
    cout << ans << " ";
  }
  cout << endl;

}

Measured memory_bytes: 188324