The war with Spain (1640–1668), the affirmation of Mafra during the reign of John V of Portugal (1706–1750) through the construction of the Palace-Convent, and later the construction of Royal Palace of Queluz in 1747 during the reigns of Joseph I (1750–1777) and Maria I (1777–1816), helped diminish royal visits to the region. During this time there were only two documented visits: in 1652 and 1654, respectively the visit of Queen Luísa de Gusmão and King John IV (1640–1656), and the final burial of King Afonso VI.