Two closed systems A (4000 kJ of thermal energy at 30°C) and B (3000 kJ of thermal energy at 40°C) are brought into contact with each other. Determine the direction of any heat transfer between the two systems and explain why.