using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var s = ReadLine(); var k = NN; var pos = 0; WriteLine(DFS(s, ref pos)[k]); } static int mod = 998_244_353; static int[][] mex = new int[][] { new int[] { 1, 2, 1 }, new int[] { 2, 0, 0 }, new int[] { 1, 0, 0 }, }; static int[][] max = new int[][] { new int[] { 0, 1, 2 }, new int[] { 1, 1, 2 }, new int[] { 2, 2, 2 }, }; static long[] DFS(string s, ref int pos) { var ans = new long[3]; if (s[pos] != 'm') { if (s[pos] == '?') ans = new long[] { 1, 1, 1 }; else ans[s[pos] - '0'] = 1; pos += 2; return ans; } var domex = s[pos + 1] != 'a'; var domax = s[pos + 1] != 'e'; long[] a; long[] b; pos += 4; a = DFS(s, ref pos); b = DFS(s, ref pos); ++pos; for (var i = 0; i < 3; ++i) for (var j = 0; j < 3; ++j) { if (domex) ans[mex[i][j]] = (ans[mex[i][j]] + a[i] * b[j] % mod) % mod; if (domax) ans[max[i][j]] = (ans[max[i][j]] + a[i] * b[j] % mod) % mod; } return ans; } }