no. of rectangles is pC2 * qC2 for obvious reasons
lets consider a right as the letter R and up as the letter U
Now for a person to move from one diagonal to the other, he has to move thro p-1 rights and q-1 ups i.e. its eqvt to arranging a sequence of p-1 R's and q-1 U's
So no. of ways is ((p-1)+(q-1))!/(p-1)!(q-1)!