It appears that the question of figuring out if a rectangle will fit inside of another, specifically at a diagonal, has been asked before. As such, utilizing the equation linked here, I was able to determine if a rectangle will fit inside of another, regardless of its angle.
However, when considering the following diagram, I am struggling to re-purpose the equation to calculate the length of side P when sides A, B, and Q are known.

It's been a few years since I've dived into algebra, but I've spent a few days trying to figure this out (where was Wolfram Alpha when I was in high school?!?).
The ultimate result would be the ability calculate angle X (see diagram) given lengths Q, A, and B.
Am I on the right track in trying to use the equation linked above? Could I be approaching this problem in a more efficient manner? I'd really appreciate any guidance anyone can provide. Thank you in advance!