The masses are pulled in only one dimension, so we can ignore the forces acting in the vertical direction. We take the positive direction to be to the right.
For the 20 kg mass, the net force is
∑ F₁ = 50 N - T
where T is the tension in string 2.
For the 40 kg mass, the net force is
∑ F₂ = T
For both masses combined, the net force is
∑ F = 50 N
Use Newton's second law to compute the acceleration of the system:
50 N = (20 kg + 40 kg) a
a = (50 N) / (60 kg) ≈ 0.83 m/s²
Then use the net force equation for the 40 kg mass to compute the tension:
T = (40 kg) a ≈ 33 N