#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

typedef long long ll;

const ll MOD = 998244353;

ll N;
string S;
ll pos = 0;
int toI[26];
ll cnt2[3][3];
ll cnt[3];

int main(){
	cin >> N >> S;
	toI['G'-'A'] = 1;
	toI['B'-'A'] = 2;
	toI['R'-'A'] = 0;
	pos = 1;
	for(ll i=1; i<=N; i++){
		pos *= i;
		pos %= MOD;
	}
	for(char c : S){
		int i = toI[c-'A'];
		int f = min((i+1)%3, (i+2)%3);
		int s = max((i+1)%3, (i+2)%3);
		if(cnt2[f][s] > 0){
			pos *= cnt2[f][s];
			pos %= MOD;
			cnt2[f][s]--;
		}
		else if(cnt[f] > 0){
			pos *= cnt[f];
			pos %= MOD;
			cnt[f]--;
			cnt2[min(f, i)][max(f,i)]++;
		}
		else if(cnt[s] > 0){
			pos *= cnt[s];
			pos %= MOD;
			cnt[s]--;
			cnt2[min(s, i)][max(s,i)]++;
		}
		else{
			cnt[i]++;
		}
	}
	cout << pos << endl;

  return 0;
}
