#include <bits/stdc++.h>
char S[300000];
int C[3] = {0}, CP[300000 / 3][3] = {0}, PB[300000] = {0};
int b, B[300000], H[300000][3] = {0}, BP;
int main() {
  int n, i, p;
  int j, pos0 = 0, pos1 = 0, pos2 = 0, fill;
  long long int pat = 1LL;
  scanf("%d", &n);
  scanf("%s", S);
  fill = 0;
  for (i = 0; i < 3 * n; i++) {
    if (S[i] == 'B') b = 1;
    if (S[i] == 'G') b = 2;
    if (S[i] == 'R') b = 4;
    H[i][0] = pos0;
    H[i][1] = pos1;
    H[i][2] = pos2;
    for (p = fill; p < n; p++) {
      if ((B[p] & b) == 0) {
        if (B[p] == 0) {
          CP[p][0] = i;
          BP = 0;
          pos0++;
        } else if ((B[p] == 1) || (B[p] == 2) || (B[p] == 4)) {
          CP[p][1] = i;
          BP = 1;
          pos1++;
        } else {
          CP[p][2] = i;
          BP = 2;
          pos2++;
        }
        B[p] |= b;
        if (B[p] == 7) {
          fill++;
          break;
        }
        break;
      }
    }
    if (BP == 0) {
      pat = pat * (n - H[i][0]);
    } else if (BP == 1) {
      pat = pat * (H[i][0] - H[i][1]);
    } else
      pat = pat * (H[i][1] - H[i][2]);
    pat = pat % 998244353;
  }
  printf("%lld\n", pat);
  return 0;
}
