Q = m*c*ΔT, where
m: mass; m = 31g
c: specific heat; c = 4.78 J/gC
ΔT: change in temperature; ΔT = 30C - 45C = -15C
Q = 31*4.78*(-15) = -2222.7 J (this is the change in heat of the Nitrogen. since this is negative, the nitrogen loses 2222.7 J of heat.)