Non-Abelian Stokes theorems in the Yang-Mills and gravity theories