=SUMPRODUCT(--(A2:A5="a"),--ISNUMBER(MATCH(MID(B2:B5,17,1),{3,4}&"",0)),--(C2:C5="XX"),D2:D5)
or, SUMIFS which is faster...
=SUM(SUMIFS(D2:D5,A2:A5,"a",B2:B5,REPT("?",16)&{3,4}&"??",C2:C5,"XX"))
or, DSUM() per Deb's post #16 which is even faster...
just change the TRUE in F3 to a