What were the main characteristics of the dynasties of the Tang (618–907) and Song (960–1279) in terms of economy, politics, and societal advancements?