#include using namespace std; // #include // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= n; ++i) #define reps(i, s, e) for (ll i = s; i <= e; ++i) #define all(v) v.begin(), v.end() using ll = long long; using ld = long double; using cp = complex; using pa = pair; using tup = tuple; using vp = vector>; using vtup = vector>; using st = string; using vs = vector; using vc = vector; using vvi = vector>; using vvc = vector>; using vi = vector; const ll MOD1 = 1000000007; const ll MOD2 = 998244353; const ll INF = (1LL << 60); int mex[3][3]; array f(int &i, string &s) { // 0, 1, 2 の場合 if (s[i] != 'm') { array res = {}; if (isdigit(s[i])) { res[s[i] - '0'] = 1; } else { res[0] = res[1] = res[2] = 1; } i++; return res; } // m?x(a,b)の場合 st m = s.substr(i, 3); i += 3; // "m?x" int type; // 1:max, 2:mex, 3:m?x if (m == "max") { type = 1; } else if (m == "mex") { type = 2; } else { type = 3; } i++; // "(" array a = f(i, s); i++; // "," array b = f(i, s); i++; // ")" array res = {}; // max if (type & 1) { rep(i, 3) rep(j, 3) { res[max(i, j)] += a[i] * b[j]; res[max(i, j)] %= MOD2; } } // mex if (type & 2) { rep(i, 3) rep(j, 3) { res[mex[i][j]] += a[i] * b[j]; res[mex[i][j]] %= MOD2; } } return res; } int main() { mex[0][0] = 1; mex[0][1] = 2; mex[0][2] = 1; mex[1][0] = 2; mex[1][1] = 0; mex[1][2] = 0; mex[2][0] = 1; mex[2][1] = 0; mex[2][2] = 0; st s; ll k; cin >> s >> k; int i = 0; array a = f(i, s); cout << a[k] << endl; }