Rotational spectroscopy of vibrationally excited N2H+ and N2D+ up to 2.7 THz