попробовать:
=ARRAYFORMULA(QUERY(QUERY({SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE({
IF(B3:F4="",,"♠"&B2:F2&"♦"&A2&"♦"&A3:A4&"♦"&B3:F4);
IF(B7:F8="",,"♠"&B6:F6&"♦"&A6&"♦"&A7:A8&"♦"&B7:F8)}),,99^99)),,99^99), "♠")), "♦")},
"select Col1,Col2,max(Col4) group by Col1,Col2 pivot Col3"),
"select Col1,Col2,Col4,Col3"))