#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &first, T2 second) {
  if (first > second) first = second;
}
template <typename T1, typename T2>
inline void chkmax(T1 &first, T2 second) {
  if (first < second) first = second;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
const int N = 3e5 + 5;
const int p = 998244353;
int mul(long long a, int b) { return a * b % p; }
int powx(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}
int n;
string s;
int R, G, B;
bool X[N], Y[N];
deque<int> que[3];
char res[6][N];
int main() {
  ios::sync_with_stdio(0);
  srand(time(0));
  int n;
  cin >> n;
  cin >> s;
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    ans = mul(ans, i);
  }
  int i = 0;
  for (auto c : s) {
    if (c == 'R') {
      ++R;
      que[0].push_back(i);
    }
    if (c == 'G') {
      ++G;
      que[1].push_back(i);
    }
    if (c == 'B') {
      ++B;
      que[2].push_back(i);
    }
    if (R && G && B) {
      assert(R == que[0].size());
      assert(G == que[1].size());
      assert(B == que[2].size());
      int L = min({que[0].front(), que[1].front(), que[2].front()});
      int R = max({que[0].back(), que[1].back(), que[2].back()});
      string form = "00";
      int M = -1;
      for (int t = 0; t < 3; ++t) {
        if (que[t].back() == R) {
          form[1] = '0' + t;
          que[t].pop_back();
        } else if (que[t].front() == L) {
          form[0] = '0' + t;
          que[t].pop_front();
        } else {
          M = que[t].front();
          que[t].pop_front();
        }
      }
      assert(M != -1);
      int id = 0;
      if (form == "01" || form == "21") {
        id = 0;
      } else if (form == "02" || form == "12") {
        id = 1;
      } else {
        id = 2;
      }
      X[L] = true;
      Y[R] = true;
      res[id][L] = s[L];
      res[id][M] = s[M];
      res[id][R] = s[R];
      --::R, --G, --B;
    }
    ++i;
  }
  for (int t = 0; t < 6; ++t) {
    int cntR = 0, cntR1 = 0;
    int cntG = 0, cntG1 = 0;
    int cntB = 0, cntB1 = 0;
    int cnt1 = 0;
    for (int i = 0; i < n * 3; ++i) {
      char c = res[t][i];
      if (c == 0) continue;
      if (X[i]) {
        if (c == 'R') ++cntR;
        if (c == 'G') ++cntG;
        if (c == 'B') ++cntB;
      } else if (!Y[i]) {
        if (cntR && c != 'R') ++cnt1, ans = mul(ans, cntR--);
        if (cntG && c != 'G') ++cnt1, ans = mul(ans, cntG--);
        if (cntB && c != 'B') ++cnt1, ans = mul(ans, cntB--);
      } else {
        ans = mul(ans, cnt1);
        --cnt1;
      }
    }
  }
  cout << ans << '\n';
}
