A tournament has 6 groups.
Each group has 4 players.
Every player will play with every player of the same group once and the top two players will qualify for the next level.
I know that each group will have 6 matches. But how to calculate that mathematically? What if there are 5, 6, 7 or 8 players in each group?