I don’t know if this option would be easier, but for me the formula
=SUMPRODUCT(IF($E$4:$J$9=$A4,$E$3:$J$3=B$3,0))
placed in cell B4 and then stretched over the entire range B4:D9 gave the same result as that of our respected colleagues Blind Spots and doubleunary