Uncertain; OED (3rd edition 2007) says that the origin of the phrase is unknown and states that a common suggestion is that the phrase originates with the distinction of the minuscule letters p and q in either the school-room or the printing-office, but goes on to say that the chronology of the senses argues against this since no such connotation is evident in the earliest quotations.
In the early 17th century, however, there is the expression pee and kew in the sense of “highest quality, best possible”{{cite-book
|year=1612
|author=Samuel Rowlands
|authorlink=Samuel Rowlands
|title=Knave of Harts
. Also recorded as in thy Pee and Kue in 1602.
Modern English dictionary
Explore and search massive catalog of over 900,000 word meanings.
Word of the Day
Get a curated memorable word every day.
Challenge yourself
Level up your vocabulary by setting personal goals.