#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	string str;
	cin >> str;

	ll res = 1;
	for (int i = 1; i <= n; ++i) res = (res * i) % MOD;

	vector<int> cou(3, 0);
	for (int i = 0; i < 3*n; ++i) {
		// Counts are x y z in increasing order, colors a b c
		// x - y have started, need b to continue
		// y - z have two, need c to complete
		// z are done
		vector<int> srt = cou;
		sort(srt.begin(), srt.end());

		int j = (str[i] == 'R' ? 0 : (str[i] == 'G' ? 1 : 2));
		if (cou[j] == srt[2]) {
			// Start
		} else if (cou[j] == srt[1]) {
			// Continue
			res = (res * (srt[2] - srt[1])) % MOD;
		} else if (cou[j] == srt[0]) {
			// Finish
			res = (res * (srt[1] - srt[0])) % MOD;
		}
		++cou[j];
	}
	cout << res << '\n';
}
