There are two heats involved:
#"heat lost by hot water + heat gained by cold water" = 0#
#color(white)(mmmmm)q_1color(white)(mmmmll) +color(white)(mmmmmm) q_2 color(white)(mmmmmll)= 0#
#color(white)(mmm)m_1C_text(s)ΔT_1 color(white)(mmm)+ color(white)(mmmm)m_2C_text(s)ΔT_2color(white)(mmmm) = 0#
Since #C_text(s)# is the same in each term, we can cancel it from the expression. Then,
#color(white)(mmmm)m_1ΔT_1 color(white)(mmml)+ color(white)(mmmmll)m_2ΔT_2color(white)(mmmm) = 0#
In this problem,
#m_1 = "40 g"; color(white)(l)T_1 = "50 °C"; ΔT_1color(white)(l) = T_text(f)color(white)(l) - "50 °C"#
#m_2 = "150 g"; T_2 = "25 °C"; ΔT_2 = T_text(f)color(white)(l) - "25 °C"#
#40 color(red)(cancel(color(black)("g"))) × (T_text(f) - "50 °C") + 150 color(red)(cancel(color(black)("g"))) × (T_text(f) - "25 °C") = 0#
#40T_text(f)-"2000 °C" + 150T_text(f) - "3750 °C" = 0#
#190T_text(f) = "5750 °C"#
#T_text(f) = "5750 °C"/190 = 30.26 °C"#
The final temperature is 30.3 °C.
Check:
#"40(30.26 - 50) + 150(30.26 - 25) = 0"#
#"40(-19.74) + 150 × 5.26 = 0"#
#"-790 + 789 = 1"#
It checks to three significant figures.