This would have been simpler if #(3m+m^2-2m-5)# were reduced to #(m^2+m-5)# but I've shown it here in its more complex form using the version given.
Note that the colors are only used to group terms with the same exponents of the variable #m#.
#{:
(ul(color(white)("x")xxcolor(white)("x")),ul(" | "),ul(3m),ul(m^2),ul(-2m),ul(-5)),
(+m^2," | ",color(red)(+3m^3),color(blue)(+m^4),color(red)(-2m^3),color(magenta)(-5m^2)),
(-5m," | ",color(magenta)(-15m^2),color(red)(-5m^3),color(magenta)(+10m^2),color(green)(+25m)),
(-6," | ",color(green)(-18m),color(magenta)(-6m^2),color(green)(+12m),color(brown)(+30))
:}#
Grouping and summing terms by powers of the variable:
#{:
(ul(color(blue)(m^4)),ul(color(red)(m^3)),ul(color(magenta)(m^2)),ul(color(green)m),ul(color(brown)("constant"))),
(+m^4,+3m^3,-5m^2,+25m,+30),
(,-2m^3,-15m^2,-18m,),
(,-5m^3,+10m^2,+`12m,),
(ul(color(white)("xxxxx")),ul(color(white)("xxx")),ul(-6m^2),ul(color(white)("xxxx")),ul(color(white)("xxxx"))),
(m^4,+4m^3,-16m^2,+19m,+30)
:}#