Google sheet formula on counting categorized data

So I have lists of items. Each items belong to different groups. And then I have data of people who has the items. And I want to count how many items of each group that person has.

For example, I have A, B, C, and D.
A and B belongs to group 1.
C belongs to group 2.
D belongs to group 3.

So I have 2 items of group 1, 1 item of group 2, and 1 item of group 3. And I have 4 items in total.

Here are the sheet for a better understanding.

Please help me because I cant figure out what the exact keyword I should search for nor do I know about advanced formulas since I’m really a newbie at this. Thank you.