In the first case, friction acts only between the 4 kg block and the 5 kg block.
So 12 N is the force required for both the blocks to move together,
Now we can write,
124=F9
After solving
F = 27 N
Hence the maximum force that can be applied on the block B is 27 N