mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline # comb init nmax = 10 ** 5 + 10 # change here fac = [0] * nmax finv = [0] * nmax inv = [0] * nmax fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, nmax): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod def comb(n, r): if n < r: return 0 else: return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod N = int(input()) S = input().rstrip('\n') ok = 0 # ABC flg = 0 for s in S: if flg == 0 and s == "A": flg = 1 elif flg == 1 and s == "B": flg = 2 elif flg == 2 and s == "C": ok = 1 break # BCA flg = 0 for s in S: if flg == 0 and s == "B": flg = 1 elif flg == 1 and s == "C": flg = 2 elif flg == 2 and s == "A": ok = 1 break # CAB flg = 0 for s in S: if flg == 0 and s == "C": flg = 1 elif flg == 1 and s == "A": flg = 2 elif flg == 2 and s == "B": ok = 1 break if not ok: print(1) exit() a = S.count("A") b = S.count("B") c = N - a - b ans = (comb(N, a) * comb(N-a, b) - a - b - c)%mod print(ans) if __name__ == '__main__': main()