Answer
(a) -87 J
(b) +87 J
Work Step by Step
(a) Let's apply the first law of thermodynamics $Q=\Delta U+W$ to find the change in the internal energy of the system.
$$Q=\Delta U+W=>\Delta U=Q-W$$
Let's plug known values into this equation.
$\Delta U=77\space J-164\space J=-87\space J$
(b) The change in the internal energy of the environment is opposite to that of the system. Therefore,
$$\Delta U_{Environment}=+87\space J$$