Following the coup, the courtiers offered Radama's queen, Rasoherina (1863–68), the opportunity to rule, if she would accept a power sharing arrangement with the Prime Minister: a new social contract that would be sealed by a political marriage between them. Queen Rasoherina accepted, first marrying Rainivoninahitriniony, then later deposing him and marrying his brother, Prime Minister Rainilaiarivony (1864–95), who would go on to marry Queen Ranavalona II (1868–83) and Queen Ranavalona III (1883–97) in succession. Over the course of Rainilaiarivony's 31-year tenure as prime minister, numerous policies were adopted to modernize and consolidate the power of the central government. Schools were constructed throughout the island and attendance was made mandatory. Army organization was improved and British consultants were employed to train and professionalize soldiers. Polygamy was outlawed and Christianity, declared the official religion of the court in 1869, was adopted alongside traditional beliefs among a growing portion of the populace. Legal codes were reformed on the basis of British common law and three European-style courts were established in the capital city. In his joint role as Commander-in-Chief, Rainilaiarivony also successfully ensured the defense of Madagascar against several French colonial incursions.