1"to be on one's P's and Q's" and variants: to be on one's best behaviour; to be at one's best, on top form; (US) to be alert, to be ‘on one's toes’.
2"to mind (also watch) one's P's and Q's": to be careful or particular in one's words or behaviour; to mind one's manners.
3"one's P's and Q's": one's alphabet, one's ‘A.B.C.’; (in extended use) knowledge or judgement, ‘one's way about’.
Early 17th century; earliest use found in Thomas Dekker (c1572–1632), playwright and pamphleteer. Origin unknown.