#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

int trans(char t) {
	if (t == 'R')return 0;
	else if (t == 'G')return 1;
	else return 2;
}
void solve() {
	int n; cin >> n;
	string s; cin >> s;
	ll c[3] = {};
	ll ans = 1;

	vector<P> l;
	rep(i, 3*n) {
		int le = i;
		while (i + 1 < 3 * n&&s[i] == s[i + 1])i++;
		l.push_back({ trans(s[i]),i - le + 1 });
	}
	ll pnum = 0;
	int num = 0;

    deque<P> v;
	rep(i, 3 * n) {

		int z = trans(s[i]);
		bool f = true;
		rep(j, 3) {
			if (j == z)continue;
			if (c[j] == 0)f = false;
		}
		if (f) {
			ll pro = 1;
			ll ma = 0;
			int chk;
			rep(j, 3) {
				if (j == z)continue;
				if (j != v[0].first) {
					chk = j;
				}
			}
			ll num = min((ll)v[0].second, c[chk]);
			//cout << i << " " << num << " " << v[0].second << endl;
			//ans = ans * num%mod; 
			ans = ans * v[0].second%mod;
			rep(j, 3) {
				if (j == z)continue;
				c[j]--;
			}
			v[0].second--; v[1].second--;
			if (v[1].second == 0) {
				P memo = v[0];
				v.pop_front();
				v.pop_front();
				if (v.size()) {
					memo.second += v.front().second;
					v.pop_front();
				}
				if (memo.second > 0) {
					v.push_front(memo);
				}
			}
			else if (v[0].second == 0) {
				v.pop_front();
			}
		}
		else {
			c[z]++;
			if (!v.empty() && v.back().first == z) {
				v.back().second++;
			}
			else {
				v.push_back({ z,1 });
			}
		}
	}
  per(i, 3 * n) {

		int z = trans(s[i]);
		bool f = true;
		rep(j, 3) {
			if (j == z)continue;
			if (c[j] == 0)f = false;
		}
		if (f) {
			ll pro = 1;
			ll ma = 0;
			int chk;
			rep(j, 3) {
				if (j == z)continue;
				if (j != v[0].first) {
					chk = j;
				}
			}
			ll num = min((ll)v[0].second, c[chk]);
			//cout << i << " " << num << " " << v[0].second << endl;
			//ans = ans * num%mod; 
			ans = ans * v[0].second%mod;
			rep(j, 3) {
				if (j == z)continue;
				c[j]--;
			}
			v[0].second--; v[1].second--;
			if (v[1].second == 0) {
				P memo = v[0];
				v.pop_front();
				v.pop_front();
				if (v.size()) {
					memo.second += v.front().second;
					v.pop_front();
				}
				if (memo.second > 0) {
					v.push_front(memo);
				}
			}
			else if (v[0].second == 0) {
				v.pop_front();
			}
		}
		else {
			c[z]++;
			if (!v.empty() && v.back().first == z) {
				v.back().second++;
			}
			else {
				v.push_back({ z,1 });
			}
		}
	}
	//cout << ans << endl;
	rep1(i, n) {
		ans = ans * i%mod;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 5640