It is said to come from the custom of innkeepers chalking up drinks so the customer could pay at the end. P stood for pint and Q for quart (two pints). If the innkeeper mixed them up he would be out of pocket. Also, P and Q in lower case are almost mirror images so it would be easy to make a mistake.