Given $A \in \mathbb R^{n\times n}$, I was told that

$$\mbox{dist}(A, \mbox{SO}(n)) = \inf\_{Q \in \mbox{SO}(n)} |A-Q| \overset ? = \inf\_{Q \in \mbox{SO}(n)} | Q^\top A - \text{Id} |$$

where we use the Frobenius norm

$$|A| := \sqrt{\text{tr}(A^\top A)}$$

I do not see why that equality holds. Clearly, $\mbox{SO}(n)=\{Q^\top P\,|\, P\in SO(n)\}$, but I do not see how this is helping, as the distance ranges over all $Q \in \mbox{SO}(n)$. Any help would be very much appreciated!