mod = 998244353 N = int(input()) S = input() dp = [[0 for _ in range(3)] for _ in range(N + 1) ] dp[0][0] = 1 for i in range(N): if S[i] == '?': for j in range(3): for k in range(10): dp[i + 1][(k + j) % 3] += dp[i][j] dp[i + 1][(k + j) % 3] %= mod if i != 0: for k in range(10): dp[i + 1][k % 3] += 1 dp[i + 1][k % 3] %= mod else: s = int(S[i]) for j in range(3): dp[i + 1][(j + s) % 3] += dp[i][j] dp[i + 1][(j + s) % 3] %= mod if i != 0: dp[i + 1][s % 3] += 1 dp[i + 1][s % 3] %= mod ans = 0 for i in range(1, N + 1): ans += dp[i][0] ans %= mod print(ans) exit()