In practice, a number of official and unofficial restrictions applied to who was able to take the imperial exams. The commoners were divided into four groups according to occupation: scholars, farmers, artisans, and merchants. Beneath the common people were the so-called "mean" people such as boat-people, beggars, sex-workers, entertainers, slaves, and low-level government employees. Among the forms of discrimination faced by the "mean" people were restriction from government office and the credential to take the imperial exam. Certain ethnic groups or castes such as the "degraded" Jin dynasty outcasts in Ningbo, around 3,000 people, were barred from taking the imperial exams as well. Women were excluded from taking the exams. Butchers and sorcerers were also excluded at times. Merchants were restricted from taking the exams until the Ming and Qing dynasties, although as early as 955, the scholar-officials themselves were involved in trading activities. During the Sui and Tang dynasties, artisans were also restricted from official service. During the Song dynasty, artisans and merchants were specifically excluded from the "jinshi" exam; and, in the Liao dynasty, physicians, diviners, butchers, and merchants were all prohibited from taking the examinations. At times, quota systems were also used to restrict the number of candidates allowed to take or to pass the imperial civil service examinations, by region or by other criteria.