Rank and inertia optimizations of two Hermitian quadratic matrix functions subject to restrictions with applications