#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 998244353


//edit
class Mint {
    using u64 = std::uint_fast64_t;
    u64 Modulus = MOD;

public:
    u64 a;

    constexpr Mint(const u64 x = 0) noexcept : a(x % Modulus) {}

    constexpr u64 &value() noexcept { return a; }

    constexpr const u64 &value() const noexcept { return a; }

    constexpr Mint operator+(const Mint rhs) const noexcept {
        return Mint(*this) += rhs;
    }

    constexpr Mint operator-(const Mint rhs) const noexcept {
        return Mint(*this) -= rhs;
    }

    constexpr Mint operator*(const Mint rhs) const noexcept {
        return Mint(*this) *= rhs;
    }

    constexpr Mint operator/(const Mint rhs) const noexcept {
        return Mint(*this) /= rhs;
    }

    constexpr Mint &operator+=(const Mint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }

    constexpr Mint &operator-=(const Mint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }

    constexpr Mint &operator*=(const Mint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }

    constexpr Mint &operator/=(Mint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    constexpr Mint &pow(int rhs) noexcept {
        u64 exp = static_cast<u64>(rhs);
        Mint base(a);
        a = 1;
        while (exp) {
            if (exp % 2) {
                *this *= base;
            }
            base *= base;
            exp /= 2;
        }
        return *this;
    }

};

class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        string S;
        cin >> 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 {
                B.push_back(i);
            }
        }

        vector<Int> X, Y, Z;
        string T(static_cast<unsigned long>(3 * N), ' ');
        for (int i = 0; i < N; ++i) {
            vector<Int> rgb = {R[i], G[i], B[i]};
            sort(all(rgb));
            X.push_back(rgb[0]);
            Y.push_back(rgb[1]);
            Z.push_back(rgb[2]);
            T[rgb[0]] = 'x';
            T[rgb[1]] = 'y';
            T[rgb[2]] = 'z';
        }

        vector<Int> cntL(3 * N), cntR(3 * N);
        for (int i = 0; i < 3 * N; ++i) {
            if (i > 0) cntL[i] = cntL[i - 1];
            if (T[i] == 'x') {
                cntL[i]++;
            } else if (T[i] == 'y') {
                cntL[i]--;
            }

            Int ri = 3 * N - i - 1;
            if (ri < 3 * N - 1) {
                cntR[ri] = cntR[ri + 1];
            }
            if (T[ri] == 'z') {
                cntR[ri]++;
            } else if (T[ri] == 'y') {
                cntR[ri]--;
            }
        }


        Mint ans = 1;
        for (int i = 1; i <= N; ++i) {
            ans *= i;
        }
        for (int i = 0; i < N; ++i) {
            Mint tmp = Mint(cntL[Y[i] - 1]) * Mint(cntR[Y[i] + 1]);
            ans *= tmp;
        }
        cout << ans.value() << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 10356