The boxes are tied together, so their motions are equal ... displacement, velocity, and acceleration ... the same for both boxes once they get going.
The force (F) exerted on Q has to be enough to accelerate the mass of both boxes.
But the force of the string pulling box-P is only enough to move the mass of box-P with the same acceleration.
So the magnitude of the force exerted on box-P by the string (the tension in the string) is <em>less than F , (but greater than zero</em>, because it accelerates box-P).
It doesn't matter which box is heavier, lighter, more mass, or less mass.