Potential energy in the first law of thermodynamics Let's say I supply heat Q to a system. If it's internal energy increases by U and the work done on it is W then by the first law of thermodynamics, Q = U + W. Now, let's say that due to the thermal expansion, the gravitational potential energy of the system also increases by P. Would it be right to say Q = U + W + P? What if the kinetic energy also increases(by K), is it right to say Q = U + W + P + K
 A: Yes.
The 1st law of thermodynamics comes from basic energy conservation covering all involved energies:**
$$E_1+W+Q=E_2\qquad\text{or rewritten:}\qquad \Delta E=W+Q $$
where $E$ represents all present energy (the sum of kinetic, potential, chemical, thermal...) and $W$ and $Q$ represent all energy added (work or heat). We could, if we wanted to, expand the formula into its parts:
$$\Delta K+\Delta U_\text{gravity}+\underbrace{\Delta U_\text{elastic}+\Delta U_\text{chemical}+\Delta E_\text{thermal}}_{\text{internal energies }\Delta U_i}+\cdots=W+Q $$
Some of these may be considered internal, such as thermal and chemical energies, and possibly elastic energy, and more and they are often grouped together and symbolised $U_i$ or similar.***
In typical thermodynamic applications (when dealing with refrigeration system, pumps, heating systems etc.), gravitational potential energies, kinetic energy and other macro-scale energies are not relevant or negligible. Therefore, typically, only internal energies are left. And that's why you most often see the 1st law of thermodynamics written like this:
$$\Delta U_i=W+Q$$


** Note that the sign convention for $W$ and $Q$ can be a bit unclear, and my use here may not match what you are used to seeing due to a different definition.
*** Depending on your system, it will vary a lot which energies that are within the system, in which case they are also covered for in the group called "internal energy". So don't take my indication here too generally.

