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 m3x{ @a=&max; @e=&mex; return map$_%MD,map$a[$_]+$e[$_],0..2; } $_=<>; y/?/3/; s/\b\d/qw(1,0,0 0,1,0 0,0,1 1,1,1)[$&]/ge; print+(eval)[<>]