Initially, switch S is at position A. The capacitor C is fully charged to charge Q:
Initial stored electrostatic energy: Ui=2CQ2
When the switch S is shifted to position B, the charged capacitor C is connected in parallel with an uncharged capacitor 3C
Total equivalent capacitance in parallel: Ceq=C+3C=4C
By conservation of charge, the total charge remains Q.
Final stored electrostatic energy: Uf=2CeqQ2=2(4C)Q2=8CQ2
Energy dissipated as heat in the circuit: ΔH=Ui−Uf
ΔH=2CQ2−8CQ2=(84−1)CQ2=83CQ2