The civil war amongst the Lê-Tr?nh and M?c dynasties ended in 1592, when the military of Tr?nh Tùng conquered Hanoi and executed king M?c M?u H?p. Survivors from the M?c royal loved ones fled into the northern mountains inside the province of Cao B?ng and continued to rule there right until 1677 when Tr?nh T?c conquered this very last M?c territo