Step 1: Apply the principle of calorimetry.
Heat lost by hot liquid \(P\) equals heat gained by cold liquid \(Q\).
\[
m_PS(\Delta T_P)
=
40(1.5S)(\Delta T_Q).
\]
Step 2: Use the given temperature relation.
Given,
\[
\Delta T_P
=
3\Delta T_Q.
\]
Substituting,
\[
m_PS(3\Delta T_Q)
=
40(1.5S)(\Delta T_Q).
\]
Cancelling \(S\) and \(\Delta T_Q\),
\[
3m_P=60,
\]
\[
m_P=20\,\mathrm{g}.
\]
Hence,
\[
\boxed{20\,\mathrm{g}}
\]
Therefore,
\[
\boxed{(B)}
\]
is the correct answer.