#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

random_device rd;
mt19937 rng(rd());

template<class T>
T randomize(T mod)
{
	return uniform_int_distribution<T>(0, mod - 1)(rng);
}

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 300013;

const int INF = 998244353;

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }
    return res;
}
int inv(int a)
{
    return pwr(a, INF - 2);
}
int dvd(int a, int b)
{
    return mul(a, inv(b));
}

int N;
int arr[MAXN];
int fw[MAXN], bw[MAXN];
int freq[3];
int tot = 0, ans = 1;
bitset<MAXN> mark;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N; string temps; cin >> temps;
    FOR(i, 0, 3 * N)
    {
        if (temps[i] == 'R') arr[i] = 0;
        if (temps[i] == 'G') arr[i] = 1;
        if (temps[i] == 'B') arr[i] = 2;
        mark[i] = true;
    }
    int iter = 0;
    FOR(i, 0, 3 * N)
    {
        freq[arr[i]]++;
        int mx = min(freq[0], min(freq[1], freq[2]));
        if (mx == iter + 1)
        {
            fw[iter] = i;
            mark[i] = false;
            iter++;
        }
    }
    fill(freq, freq + 3, 0);
    iter = 0;
    FORD(i, 3 * N, 0)
    {
        freq[arr[i]]++;
        int mx = min(freq[0], min(freq[1], freq[2]));
        if (mx == iter + 1)
        {
            bw[iter] = i;
            mark[i] = false;
            iter++;
        }
    }
    fill(freq, freq + 3, 0);
    FOR(i, 0, 3 * N)
    {
        freq[arr[i]]++;
        if (mark[i])
        {
            //one of them !+ arr[i] will be positive
            int res = -1;
            FOR(j, 0, 3)
            {
                if (j != arr[i] && freq[j] > 0) res = j;
            }
            ans = mul(ans, freq[res]);
            FOR(j, 0, 3) freq[j]--;
        }
    }
    fill(freq, freq + 3, 0);
    FORD(i, 3 * N, 0)
    {
        freq[arr[i]]++;
        if (mark[i])
        {
            //one of them !+ arr[i] will be positive
            int res = -1;
            FOR(j, 0, 3)
            {
                if (j != arr[i] && freq[j] > 0) res = j;
            }
            ans = mul(ans, freq[res]);
            FOR(j, 0, 3) freq[j]--;
        }
    }
    FOR(i, 1, N + 1)
    {
        ans = mul(ans, i);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2708