from collections import defaultdict import bisect mod = 998244353 S = input() N = len(S) K = int(input()) sep = defaultdict(list) brac = [0] * N for i in range(1, N): if S[i] == "(": brac[i] = brac[i-1] + 1 elif S[i] == ")": brac[i] = brac[i-1] - 1 else: brac[i] = brac[i-1] if S[i] == ",": sep[brac[i]].append(i) for k, v in sep.items(): print(k, v) def mex(a, b): for i in range(3): if not i in [a, b]: return i def rec(L, R): if L + 1 >= R: if S[L] == "?": return [1, 1, 1] res = [0, 0, 0] res[int(S[L])] += 1 return res R -= 1 L += 1 oper = [] if S[L] == "?" or S[L] == "a": oper.append(max) if S[L] == "?" or S[L] == "e": oper.append(mex) L += 3 dep = brac[L] p = bisect.bisect_left(sep[dep], L) M = sep[dep][p] A = rec(L, M) B = rec(M+1, R) res = [0, 0, 0] for op in oper: for i, a in enumerate(A): for j, b in enumerate(B): idx = op(i, j) res[idx] += a * b % mod res[idx] %= mod return res ans = rec(0, N)[K] print(ans)