#include #include using namespace std; const int MOD = 998244353; const int MAX = 2e5+10; int ans[3][MAX]={}; int mex(int i,int j){ if(i!=0 and j!=0) return 0; if(i!=1 and j!=1) return 1; return 2; } void number(string& s,int& p){ if(isdigit(s[p])){ ans[s[p]-'0'][p]=1; }else{ assert(s[p]=='?'); ans[0][p]=ans[1][p]=ans[2][p]=1; } p++; } void expression(string& s,int& p){ if(s[p]!='m'){ number(s,p); return; } int x=p; assert(s[p]=='m' and s[p+2]=='x' and s[p+3]=='('); char c=s[p+1]; assert(c=='a' or c=='e' or c=='?'); p+=4; int y=p; expression(s,p); assert(s[p]==','); p+=1; int z=p; expression(s,p); assert(s[p]==')'); p+=1; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ if(c=='a' or c=='?'){ ans[max(i,j)][x]+=1ULL*ans[i][y]*ans[j][z]%MOD; ans[max(i,j)][x]%=MOD; } if(c=='e' or c=='?'){ ans[mex(i,j)][x]+=1ULL*ans[i][y]*ans[j][z]%MOD; ans[mex(i,j)][x]%=MOD; } } } } //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin>>s; int p=0; expression(s,p); int k; cin>>k; cout<