In the UK, the phrase means to mind one’s manners or to behave properly. This reflects its historical meaning. However, in the US, according to the Oxford English Dictionary, it can also mean to be alert, to be on one’s toes, to be on top form.
Many explanations have been advanced down the decades to explain this puzzling expression. It is said to be advice to a child learning its letters to be careful not to mix up the handwritten lower-case letters p and q, or similar advice to a printer’s apprentice, for whom the backward-facing metal type letters would be especially confusing. One has to wonder why p and q were singled out, when similar problems occur with b and d. Others have argued that, closely fitting the “mind your manners” sense, it might just have been an abbreviation of mind your pleases and thank-yous, a view advanced in particular by some dictionaries.
We may leave out of account more fanciful suggestions, such that it was an instruction from a French dancing master to be sure to perform the dance figures pieds and queues accurately, that it was an admonishment to seamen not to soil their navy pea-jackets with their tarred queues (their pigtails), or that it was jocular, or perhaps deadly serious, advice to a barman not to confuse the letters p and q on the tally slate, on which the letters stood for the pints and quarts consumed “on tick” by the patrons, even though men did indeed at one time consume beer by the quart.
To confuse the matter somewhat, we also have examples of a closely similar expression, P and Q or pee and kew. This was seventeenth-century slang and meant “highest quality”; it was later recorded in dialect (the English Dialect Dictionary reports it in Victorian times from Shropshire and Herefordshire). The Oxford English Dictionary has a citation from Rowlands’ Knave of Harts of 1612: “Bring in a quart of Maligo, right true: And looke, you Rogue, that it be Pee and Kew.” Nobody is really sure what either P or Q stood for. To say they’re the initials of “Prime Quality” seems to be folk etymology, because surely that would make “PQ” rather than “P and Q”.
Investigations by the Oxford English Dictionary in 2007 when revising the entry turned up early examples of the use of Ps and Qs to mean learning the alphabet. The first is in a poem by Charles Churchill, published in 1763: “On all occasions next the chair / He stands for service of the Mayor, / And to instruct him how to use / His A’s and B’s, and P’s and Q’s.” The conclusion must be that this is the true origin.