#include <bits/stdc++.h>

using namespace std;

const int MX = 300000, md = 998244353;

char s[MX + 1];

int f[MX];

int main() {
	int n;
	ignore = scanf("%d %s", &n, s);
	
	for (int r = 0, g = 0, b = 0, i = 0; i < n; i++, r++, g++, b++) {
		while (s[r] != 'R') r++;
		while (s[g] != 'G') g++;
		while (s[b] != 'B') b++;
		
		int L = min({r, g, b});
		int R = max({r, g, b});
		int C = r + g + b - L - R;
		
		f[L] = -1;
		f[C] = 0;
		f[R] = 1;
	}
	
	int ans = 1;
	for (int i = 1; i <= n; i++) ans = ans * 1ll * i % md;
	
	for (int i = 0, x = 0; i < 3 * n; i++) {
		if (f[i] == -1) x++;
		if (f[i] == 0) {
			ans = ans * 1ll * x % md;
			x--;
		}
	}
	
	for (int i = 3 * n - 1, x = 0; i >= 0; i--) {
		if (f[i] == 1) x++;
		if (f[i] == 0) {
			ans = ans * 1ll * x % md;
			x--;
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}
