#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

constexpr int MAXN = 1e5 + 42, MOD = 998244353;

ll open[4][4];

int main() {
  int N;
  string S;
  cin >> N >> S;
  ll res = 1;
  for (int i = 1; i <= N; i++) {
    res *= i;
    res %= MOD;
  }
  for (char c : S) {
    int x = (c == 'R' ? 2 : c == 'B') + 1;
    int can = 0;
    int ok1 = 0, ok2 = 0;
    for (int i = 1; i <= 3; i++) {
      for (int j = 1; j <= 3; j++) {
        if (i != x && j != x && open[i][j]) {
          can += open[i][j];
          ok1 = i;
          ok2 = j;
        }
      }
    }
    if (can) {
      res *= can;
      res %= MOD;
      open[ok1][ok2]--;
      continue;
    }
    for (int i = 1; i <= 3; i++) {
      if (i != x && open[i][0]) {
        can += open[i][0];
        ok1 = i;
      }
    }
    if (can) {
      res *= can;
      res %= MOD;
      open[ok1][0]--;
      open[ok1][x]++;
    } else {
      open[x][0]++;
    }
  }

  cout << res << endl;

  return 0;
}
