Loot flows from the leader
The DMG section on Treasure is a bit jumbled, probably because they had to fit in a bunch of tables and I know from experience that's hard to do. There's is however guidance on how to use the tables.
From page 133 of the DMG:
When determining the contents of a hoard belonging to one monster, use the table that corresponds to that monster's challenge rating. When rolling to determine a treasure hoard belonging to a large group of monsters, use the challenge rating of the monster that leads the group. If the hoard belongs to no one, use the challenge rating of the monster that presides over the dungeon or lair you are stocking. If the hoard is a gift from a benefactor, use the challenge rating equal to the party's average level.
These tables include entries where you roll on Magic Item Table X N times (X = A, B, C, ...) and N is determined by a die roll. This is clarified ahead of these tables aswell:
When you use a Treasure Hoard table to randomly determine the contents of a treasure hoard and your roll indicates the presence of one or more magic items, you can determine the specific magic items by rolling on the appropriate table(s) here.
— Dungeon Master's Guide, p. 144