Shahi dynasty ruled the Kabul Valley and Gandhara from third century to the early 10th century .