#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __DJKIM613
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

long long MOD = 998244353;
struct mod_cal{
  long long val;
  mod_cal(long long val) : val(val) {}

  mod_cal operator + (const mod_cal x) const{
    return (val + x.val) % MOD;
  }

  mod_cal operator - (const mod_cal x) const{
    return (val - x.val + MOD) % MOD;
  }

  mod_cal operator * (const mod_cal x) const{
    return val * x.val % MOD; 
  }
};

mod_cal mod_pow(mod_cal x, long long y){
  mod_cal ret = mod_cal(1);
  while(y){
    if(y & 1) ret = ret * x;
      x = x * x;  y >>= 1;
  }
  return ret;
}

int N;
string s;

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> s;

    int X = 0, Y = 0, Z = 0;
    int R = 0, G = 0, B = 0;
    mod_cal res = 1;

    rep(i, 3*N) {
        int typ = 0;
        if (s[i] == 'R') {
            if (R >= G and R >= B) typ = 1;
            else if (G > 0 and B > 0) typ = 3, R--, B--, G--;
            else typ = 2;
            R++;
        } else if (s[i] == 'G') {
            if (G >= R and G >= B) typ = 1;
            else if (R > 0 and B > 0) typ = 3, R--, B--, G--;
            else typ = 2;
            G++;
        } else {
            if (B >= R and B >= G) typ = 1;
            else if (R > 0 and G > 0) typ = 3, R--, B--, G--;
            else typ = 2;
            B++;
        }
        debug(typ);
        if (typ == 1) X++;
        else if (typ == 2) res = res*X--, Y++;
        else res = res*Y--;
    }
    debug(res.val);
    rep(i, N) res = res*N--;
    cout << res.val << endl;
}

Measured memory_bytes: 720