sub MD{998244353} sub max{ ($a,$b,$c,$d,$e,$f)=@_; return map$_%MD,$a*$d,$a*$e+$b*$d+$b*$e,$a*$f+$b*$f+$c*$d+$c*$e+$c*$f; } sub mex{ ($a,$b,$c,$d,$e,$f)=@_; return map$_%MD,$b*$e+$b*$f+$c*$e+$c*$f,$a*$d+$a*$f+$c*$d,$a*$e+$b*$d; } sub mx{ @a=max(@_); @e=mex(@_); return map$_%MD,map$a[$_]+$e[$_],0..2; } $_=<>; s/\b\?//g; s/\d/qw(1,0,0 0,1,0 0,0,1)[$&]/ge; s/\?/1,1,1/g; print+(eval)[<>]