Second, the number of groups must be less than or equal to n, so as to ensure that each group and each department has a team.
Therefore, it can only be divided into n groups, and it is enough to put n teams of different levels in each department into these n groups. Each team, if randomly placed, will become a mixed race.
The specific method is to make the drawbar into n blocks 1-n, and n teams from each department draw lots together. Those who draw 1 enter each group, those who draw 2 enter the second group, and so on.
The following group matches should be set according to the number of teams in each group and the competition rules you set (round robin or knockout), which is uncertain here.