Dynamics of triple black hole systems in hierarchically merging massive galaxies