Ok, it is pretty simple, just having a slow day.
First n is rotated to be (0,1,0) {could have been parallel to any axes} using rotation matrix A.
Point p is then rotated around (0,0,0) using the same matrix to become p'.
The x & z components of p' are set to zero to become p", which now lies on the y axis. The distance to p" is simply the y component of p' (or p").