This is the formula in cell G9. The formula is filled up and confirmed with ctrl+shift+enter because i work with legacy Excel 2013. Not 100 % sure if this does what you want but that's how i understand the task.
=SUM(COUNTIFS($B$2:$B$18,F9,$C$2:$C$18,IF($B$2:$B$18=E9,$C$2:$C$18)))