Abcd is a square, so we can rotate the triangle APB counterclockwise by 90 degrees with A as the rotation center, so that AB and AD coincide, and P is point M, so the angle MAQ= angle QAB, and because AB//BC and angle MQA= angle QAB, so
Angle MAQ= angle MQA, so AM=QM, because AP=AM, QM=QD+BP, so AP=QD+BP.
The second way is under consideration.