How to know in which direction tension acts on pulleys where multiple masses are connected through multiple pulleys?
The direction of tension in a rope or string is always parallel to the direction of the rope/string itself, and acts in the direction that would lengthen the rope/string. If the internal force acted in the opposite direction then it would be called compression, not tension - and ropes/strings cannot support a compressive load.
If the rope/ string goes round a pulley then it exerts two tangential forces on the pulley; one along the tangent where it enters the pulley and one along the tangent where it leaves. If the rope/string is light (effectively massless) and there is no friction between it and the pulley then these two forces will be equal in magnitude, although they may act in different directions, depending on the geometry of the scenario.
In general, if you are unsure whether a force acts in one of two opposite directions (to the right or the left, say) , make an assumption (so pick right, for example) and solve the problem. If the magnitude of the force turns out to be negative then it acts in the opposite direction to the one you picked.