//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<998244353>;

int getc(char c) {
    if (c == 'R') return 0;
    if (c == 'G') return 1;
    if (c == 'B') return 2;
    return false;
}
using A = array<int, 3>;
ostream& operator<<(ostream& os, const A& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

A norm(A a) {
    int u = min({a[0], a[1], a[2]});
    for (int i = 0; i < 3; i++) {
        a[i] -= u;
    }
    return a;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    string s;
    cin >> s;
    V<int> di(3 * n + 1, n);
    di[0] = di[3 * n] = 0;
    {
        A le = {0, 0, 0};
        for (int i = 0; i < 3 * n - 1; i++) {
            int ty = getc(s[i]);
            le[ty]++;
            di[i + 1] -= min({le[0], le[1], le[2]});
            di[i + 1] -= n - max({le[0], le[1], le[2]});
        }
    }
    dbg(di);

    V<int> dir(3 * n, 0);
    for (int i = 0; i < 3 * n; i++) {
        if (di[i] < di[i + 1]) dir[i] = 1;
        else if (di[i] > di[i + 1]) dir[i] = -1;
    }
    dbg(dir);

    Mint ans = Mint(1);    
    for (int ph = 0; ph < 2; ph++) {
        A le = {0, 0, 0};
        A ri = {n, n, n};    
        A rem = {0, 0, 0};
        for (int i = 0; i < 3 * n; i++) {
            int ty = getc(s[i]);

            ri[ty]--;
            A le2 = norm(le);
            A ri2 = norm(ri);
            le[ty]++;

            dbg(rem);

            le2[ty] = ri2[ty] = 0;
            
            // c .. x .. y
            if (dir[i] == 1) {
                rem[ty]++;
                continue;
            }
            // x .. y .. c
            if (dir[i] == -1) continue;
            
            
            int lid = (ty + 1) % 3;
            if (!rem[lid]) lid = (lid + 1) % 3;
            assert(rem[lid]);

            ans *= rem[lid];
            rem[lid]--;
        }
        dbg(ans);
        reverse(s.begin(), s.end());
        reverse(dir.begin(), dir.end());
        for (auto& d: dir) d *= -1;
    }
    for (int i = 1; i <= n; i++) ans *= Mint(i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2964