#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
string t;
int sa, sb, sc;
int ea, eb, ec;
int a, b, c;
bool s[400000], e[400000];
signed main() {
	cin >> n >> t;
	n = 3 * n;
	for (int i = 0; i < n; i++) {
		if (t[i] == 'R') {
			a++;
			if (sb + sc < a - sa) {
				sa++;
				s[i] = 1;
			}
		}
		else if (t[i] == 'G') {
			b++;
			if (sa + sc < b - sb) {
				sb++;
				s[i] = 1;
			}
		}
		else {
			c++;
			if (sa + sb < c - sc) {
				sc++;
				s[i] = 1;
			}
		}
	}
	sa = 0, sb = 0, sc = 0, a = 0, b = 0, c = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (t[i] == 'R') {
			a++;
			if (!s[i] && sb + sc < a - sa) {
				sa++;
				e[i] = 1;
			}
		}
		else if (t[i] == 'G') {
			b++;
			if (!s[i] && sa + sc < b - sb) {
				sb++;
				e[i] = 1;
			}
		}
		else {
			c++;
			if (!s[i] && sa + sb < c - sc) {
				sc++;
				e[i] = 1;
			}
		}
	}
	sa = 0, sb = 0, sc = 0;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		if (s[i]) {
			if (t[i] == 'R') sb++, sc++;
			else if (t[i] == 'G') sa++, sc++;
			else sa++, sb++;
		}
		else {
			if (t[i] == 'R') {
				if (!e[i])(ans *= sa) %= mod;
				sa--;
			}
			else if (t[i] == 'G') {
				if (!e[i])(ans *= sb) %= mod;
				sb--;
			}
			else {
				if (!e[i])(ans *= sc) %= mod;
				sc--;
			}
		}
	}
	sa = 0, sb = 0, sc = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (e[i]) {
			if (t[i] == 'R') sb++, sc++;
			else if (t[i] == 'G') sa++, sc++;
			else sa++, sb++;
		}
		else {
			if (t[i] == 'R') {
				if(!s[i])(ans *= sa) %= mod;
				sa--;
			}
			else if (t[i] == 'G') {
				if (!s[i])(ans *= sb) %= mod;
				sb--;
			}
			else {
				if (!s[i])(ans *= sc) %= mod;
				sc--;
			}
		}
	}
	for (int i = 1; i <= n / 3; i++) {
		(ans *= i) %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1284