Between the 9th and 10th centuries, the Andorran valleys belonged to the counts of Urgell, who ceded them to the See of Urgell in 988 in exchange for other possessions in the Cerdanya, although it was not until the 12th century that Andorrans recognised the sovereignty of the See of Urgell in an agreement signed with the bishop Bernat Sanç in 1176.