For the first table, in g2 and copy down and across this Array(control+shift+enter-not just enter) formula.

=IFERROR(INDEX(C$2:C$10;SMALL(IF($B$2:$B$10=$F$1;ROW(C$2:C$10)-1);ROW(C1)));"")

If you need change all semi colons in my formula to comma.