Answer
Heat would flow from B to A.
Work Step by Step
Heat flows from the higher temperature systems/bodies into the systems/bodies with lower temperature (if they are in thermal contact), until they reach thermal equilibrium (same temperature).
In this case, heat would flow from the sytem $B (50^{\circ}C)$ into A $(20 ^{\circ}C)$. The fact that system A has a higher thermal energy content is irrelevant to this process.