=SUMIFS($F$3:$F$7,$A$3:$A$7,A12,$B$3:$B$7,B12,$C$3:$C$7,C12,$D$3:$D$7,TRIM(D12&E12),$E$3:$E$7,TRIM(F12&G12))
and by the way.. little modification is HUI's formula..
=SUMPRODUCT(($A$3:$A$7=A12)*($B$3:$B$7=B12)*($C$3:$C$7=C12)*(($D$3:$D$7=D12)+($D$3:$D$7=E12))*(($E$3:$E$7=F12)+($E$3:$E$7=G12)),$F$3:$F$7)