import sys input = sys.stdin.readline N = int(input()) S = input()[:-1] dp = [[0]*3 for _ in range(2)] dp[0][0] = 1 ans = 0 MOD = 998244353 for Si in S: ndp = [[0]*3 for _ in range(2)] for i in range(3): ndp[0][i] = dp[0][i] if Si=='?': nums = list(range(10)) else: nums = [int(Si)] for i in range(2): for j in range(3): for num in nums: nj = (j+num)%3 ndp[1][nj] += dp[i][j] ndp[1][nj] %= MOD dp = ndp ans += dp[1][0] ans %= MOD print(ans)