In G2 use
=TREND($B2:F2,$B1:F1,G1)
Copy across till M2

In N2
=INDEX(B1:M1,MATCH(P2,B2:M2)+1)

Does this help?