#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll solve(int n, const string& s) {
    vector<int> cnt(8, 0);
    ll ans = 1;
    for (int i = 1; i <= n; i++) {
        (ans *= i) %= MOD;
    }

    for (int i = 0; i < 3 * n; i++) {
        int hoge = 0;
        if (s[i] == 'R') {
            hoge = 1;
        } else if (s[i] == 'G') {
            hoge = 2;
        } else {
            hoge = 4;
        }

        if (cnt[7 ^ hoge] > 0) {
            (ans *= cnt[7 ^ hoge]) %= MOD;
            cnt[7 ^ hoge]--;
            cnt[7]++;
        } else {
            bool f = false;
            for (int j : {1, 2, 4}) {
                if (j == hoge) continue;
                if (cnt[j] > 0) {
                    f = true;
                    (ans *= cnt[j]) %= MOD;
                    cnt[j]--;
                    cnt[j ^ hoge]++;
                }
            }

            if (!f) {
                cnt[hoge]++;
            }
        }
    }
    return ans; 
}

ll solveTLE(int n, const string& s) {
    vector<int> r, g, b;
    for (int i = 0; i < 3 * n; i++) {
        if (s[i] == 'R') r.push_back(i);
        else if (s[i] == 'G') g.push_back(i);
        else if (s[i] == 'B') b.push_back(i);
    }

    int minv = 114514;
    ll ans = 0;
    vector<int> rr, gg, bb;
    do {
        do {
            do {
                int val = 0;
                for (int i = 0; i < n; i++) {
                    int hoge = max({r[i], g[i], b[i]});
                    int foo = min({r[i], g[i], b[i]});
                    val += hoge - foo;
                }
                if (minv > val) {
                    minv = val;
                    ans = 1;
                    /*
                    rr = r;
                    gg = g;
                    bb = b;
                    //*/
                } else if (val == minv) {
                    ans++;
                }
            } while (next_permutation(b.begin(), b.end()));   
        } while (next_permutation(g.begin(), g.end()));        
    } while (next_permutation(r.begin(), r.end()));
    /*
    cout << minv << endl;
    for (int i = 0; i < n; i++) {
        cout << r[i] << " " << g[i] << " " << b[i] << endl;
    }//*/
    return ans;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //*
    int n;
    cin >> n;
    string s;
    cin >> s;
    //*/

    cout << solve(n, s) << "\n";

    /*
    int n = 5;
    string s = string(n, 'B') + string(n, 'G') + string(n, 'R');
    random_device rnd;
    mt19937 mt(rnd());
    for (int i = 0; i < 100; i++) {
        shuffle(s.begin(), s.end(), mt);
        ll ans1 = solve(n, s);
        ll ans2 = solveTLE(n, s);
        if (ans1 != ans2) {
            cout << s << endl;
            cout << ans1 << " " << ans2 << endl;
            break;
        }
    }//*/

    /*
    vector<int> r, g, b;
    for (int i = 0; i < 3 * n; i++) {
        if (s[i] == 'R') r.push_back(i);
        else if (s[i] == 'G') g.push_back(i);
        else if (s[i] == 'B') b.push_back(i);
    }

    int minv = 114514;
    vector<int> rr, gg, bb;
    do {
        do {
            do {
                int val = 0;
                for (int i = 0; i < n; i++) {
                    int hoge = max({r[i], g[i], b[i]});
                    int foo = min({r[i], g[i], b[i]});
                    val += hoge - foo;
                }
                if (minv > val) {
                    minv = val;
                    rr = r;
                    gg = g;
                    bb = b;
                }
            } while (next_permutation(b.begin(), b.end()));   
        } while (next_permutation(g.begin(), g.end()));        
    } while (next_permutation(r.begin(), r.end()));
    cout << minv << endl;
    for (int i = 0; i < n; i++) {
        cout << r[i] << " " << g[i] << " " << b[i] << endl;
    }//*/
    return 0;
}

Measured memory_bytes: 720