Immiscible three-phase flow in porous media: dynamics and wettability effects at the pore scale