#define MD 998244353 struct S{ Mint k; int n; char a[50],b[50]; }; S q[100000]; { ll@n; ll tn; char t[51]; rd(t@tn); rep(i,n){ ll sn; char s[100001]; rd(s@sn); if(*s=='~'){ ll@--j,@--k; { ll l=max(0,min(tn-1-q[j].n,q[k].n)); memcpy(q[i].a,q[j].a,q[j].n); memcpy(q[i].a+q[j].n,q[k].a,l); } { ll l=max(0,min(tn-1-q[k].n,q[j].n)); memcpy(q[i].b,q[j].b+q[j].n-l,l); memcpy(q[i].b+l,q[k].b,q[k].n); } q[i].n=min(tn-1,q[j].n+q[k].n); memcpy(s,q[j].b,q[j].n); memcpy(s+q[j].n,q[k].a,q[k].n); sn=q[j].n+q[k].n; q[i].k=q[j].k+q[k].k; }else{ if(sn