When people first studied heat, they didn’t know it was a type of energy flow: instead they thought it was caused by the flow of something called the “caloric fluid”. Over the early 1800s they came to formulate something called the First Law of Thermodynamics, which said that “the change of a system’s energy is equal to the work that is done on the system plus the heat that flows into the system.” In equation form
$$\Delta E=W+Q$$
where $Q$ is the symbol typically used for heat.
Now that we know that heat is a type of energy flow, we can see that this is simply a restatement of the Law of Conservation of Energy. In this example:
30J of heat flow into a system, so $Q=+30\u{J}$
10J of work flow out of the system, so $W=-10\u{J}$
then the system’s energy changes by $\Delta E=+20\u{J} = +30\u{J} - 10\u{J}$, the sum of the work and the heat.