how Madrid became the capital