This axiom, regardless of its origins, has been
common in post-victorian
Britain as an abbreviation of 'to mind your manners' or, more specifically, to say both 'please' (p's) and 'thankyou' (thank-Q).
Thus the phrase 'watch your p's and q's' has been in use to encourage people to speak politely, especially
children, who remember such phrases better than just instructions.