Heat and work are treated as path functions in thermodynamics
$\Delta Q =\Delta U +\Delta W$
Since work done by gas depends on type of process i.e. path and $\Delta U$ depends just on initial and final states, so $\Delta Q$ i.e. heat, also has to depend on process is path.