In many places he appears as the first King of Navarre and in others the third; however, he was at least the seventh king of Pamplona. During the late 10th century, Almanzor, the ruler of Al Andalus, frequently led raids against the Christian kingdoms, and attacked the Pamplonese lands on at least nine occasions. In 966, clashes between the Islamic factions and the Kingdom resulted in the loss of Calahorra and the valley of the river Cidacos. Sancho II, while allied with Castilian militias, suffered a grave defeat in the Battle of Torrevicente. Sancho II was forced to hand over one of his daughters and one of his sons as tokens of peace. After the death of Sancho II and during the reign of García Sánchez II, Pamplona was attacked by the Caliphate on several occasions, being completely destroyed in 999, the King himself killed during a raid in the year 1000. After the death of García Sánchez II, the crown passed to Sancho III, just eight years old at the time, and probably completely controlled by the Caliphate. During the first years of his reign the Kingdom was ruled by his cousins Sancho and García of Viguera until the year 1004, when Sancho III would become ruling king, mentored by his mother Jimena Fernández. The links with Castile became stronger through marriages. The death of Almanzor in 1002 and his successor Abd al-Malik ibn Marwan in 1008 caused the decline of the Caliphate of Córdoba and the progress of the County of Castile south, while Pamplona, led by Sancho Garcés III, strengthen the position of his kingdom on the borderlands of the Taifa of Zaragoza, controlling the territories of Loarre, Funes, Sos, Uncastillo, Arlas, Caparroso and Boltaña. In the year 1011 Sancho III married Muniadona of Castile, daughter of the Count of Castile Sancho García. In 1016 the County of Castile and the Kingdom of Navarre made a pact on their future expansion: Pamplona would expand towards the south and east, the eastern region of Soria and the Ebro valley, including territories that were at the time part of Zaragoza. Thus, the Kingdom of Pamplona comprised a territory of 15,000 km² between Pamplona, Nájera and Aragón with vassals of Pamplonese and Aragonese origin.