Assuming worst case scenario.
Assuming data starts in A3
Use this ARRAYED function in C3 copied down

=IF(SUMPRODUCT(($A$3:A3=A3)*($B$3:$B3=B3))=1, A3&"_"&SUMPRODUCT(($F$2:$F2<>"")/COUNTIF($F$2:F2,$F$2:$F2&""))+1,INDEX($F$3:F3,MATCH(A3&B3,$A$3:$A3&$B$3:B3,0)))

...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.