If I consider a heat engine H$\mathrm{H}$ and a refrigerator R$\mathrm{R}$ such that:
where Q1<Q'1$Q_1<Q'_1$ and Q2<Q'2$Q_2<Q'_2$. Now
Now if we were to connect the engine and the refrigerator in the following way :
We notice that Q1=W+Q2 and Q'1=W+Q'2 by :
(a) $Q_1=W+Q_2$
(b) $Q'_1=W+Q'_2$
(by the conservation of energy. From)
From some manipulations of these equations we, we arrive at : Q'1-Q1=Q'2-Q2.
$$Q'_1-Q_1=Q'_2-Q_2$$
Now if we were to draw a box around the refrigerator and the engine and in turn call it the new refrigerator, we see that :
Where I have defined Q=Q'1-Q1=Q'2-Q2$Q=Q'_1-Q_1=Q'_2-Q_2$. The resulting refrigerator that we get has the ability to transfer heat from the hot body to the cold body without the help of any external work, which is a violation of the second law of thermodynamics.
(When I asked the above question in other places, the response was that just like perpetual machines, such a configuration, although might seem to work on paper, cannot exist in real life. Is this what the answer should be?)