import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


# 解説AC
N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


def test():
    pos = {'R': [], 'G': [], 'B': []}
    for i, s in enumerate(S):
        pos[s].append(i)
    ret = IINF
    for r in itertools.permutations(pos['R']):
        for g in itertools.permutations(pos['G']):
            for b in itertools.permutations(pos['B']):
                s = 0
                for i in range(N):
                    s += max(r[i], g[i], b[i]) - min(r[i], g[i], b[i])
                ret = min(ret, s)
    return ret


def test2():
    counter = {'R': 0, 'G': 0, 'B': 0}

    L = []
    R = []
    for i, c in enumerate(S):
        pm = max(counter.values())
        counter[c] += 1
        if pm < max(counter.values()):
            L.append(i)
        if min(counter.values()) == 1:
            R.append(i)
            for d in counter.keys():
                counter[d] -= 1
    L = np.array(L)
    R = np.array(R)
    s = (R - L).sum()
    return s


# N = 4
#
# i = 0
# for rs in itertools.combinations(range(N * 3), r=N):
#     s = ['G'] * (N * 3)
#     for r in rs:
#         s[r] = 'R'
#     rem = list(set(range(N * 3)) - set(rs))
#     for bs in itertools.combinations(range(N * 2), r=N):
#         t = s.copy()
#         for b in bs:
#             t[rem[b]] = 'B'
#         S = ''.join(t)
#         a = test()
#         b = test2()
#         assert a == b
#
#         if i % 100 == 0:
#             print(i)
#         i += 1


def get_lr():
    counter = {'R': 0, 'G': 0, 'B': 0}

    L = []
    R = []
    for i, c in enumerate(S):
        pm = max(counter.values())
        counter[c] += 1
        if pm < max(counter.values()):
            L.append(i)
        if min(counter.values()) == 1:
            R.append(i)
            for d in counter.keys():
                counter[d] -= 1
    L = np.array(L)
    R = np.array(R)
    # s = (R - L).sum()
    return L, R


# 左右は絶対ここから選ぶ
L, R = get_lr()

colors = np.array(list(S))
lmr = np.array(['M'] * (N * 3), dtype=str)
lmr[L] = 'L'
lmr[R] = 'R'
# 左から L, M, R の順に選ぶ組み合わせ


counts = {
    'R': 0,
    'G': 0,
    'B': 0,
}
# これより右にある、使える lmr == R の数
r_counts = np.zeros(N * 3, dtype=int)
# これより左にある、使える lmr == L の数
l_counts = np.zeros(N * 3, dtype=int)
for i in range(N * 3):
    if lmr[i] == 'L':
        counts[colors[i]] += 1
    if lmr[i] == 'M':
        if colors[i] == 'R':
            # B か G のどっちかしかない
            if counts['B']:
                l_counts[i] = counts['B']
                # 使ったので 1 減らす
                counts['B'] -= 1
            elif counts['G']:
                l_counts[i] = counts['G']
                counts['G'] -= 1
            else:
                assert False
        if colors[i] == 'G':
            if counts['B']:
                l_counts[i] = counts['B']
                counts['B'] -= 1
            elif counts['R']:
                l_counts[i] = counts['R']
                counts['R'] -= 1
            else:
                assert False
        if colors[i] == 'B':
            if counts['R']:
                l_counts[i] = counts['R']
                counts['R'] -= 1
            elif counts['G']:
                l_counts[i] = counts['G']
                counts['G'] -= 1
            else:
                assert False
for i in reversed(range(N * 3)):
    if lmr[i] == 'R':
        counts[colors[i]] += 1
    if lmr[i] == 'M':
        if colors[i] == 'R':
            if counts['B']:
                r_counts[i] = counts['B']
                counts['B'] -= 1
            elif counts['G']:
                r_counts[i] = counts['G']
                counts['G'] -= 1
            else:
                assert False
        if colors[i] == 'G':
            if counts['B']:
                r_counts[i] = counts['B']
                counts['B'] -= 1
            elif counts['R']:
                r_counts[i] = counts['R']
                counts['R'] -= 1
            else:
                assert False
        if colors[i] == 'B':
            if counts['R']:
                r_counts[i] = counts['R']
                counts['R'] -= 1
            elif counts['G']:
                r_counts[i] = counts['G']
                counts['G'] -= 1
            else:
                assert False

ans = 1
for cnt in (l_counts * r_counts):
    if cnt:
        ans *= cnt
        ans %= MOD
# N! 人に割り当てる
for i in range(1, N + 1):
    ans *= i
    ans %= MOD
print(ans)


Measured memory_bytes: 25152