On the standard typewriter the letters p and q are at opposite ends of the keyboard. Novices at typing cam get the location of these two letters mixed up. Also as one can see in lower case p and q are mirror images of each other.
They don't stand for anything. The saying means that you should be attentive to what you are doing to not make a mistake. It comes from the common mistake of writing a p for a q (or vice versa) because they look so similar on paper.
Sometimes people write lowercase P's and Q's wrong. That's part of it. Like pq, they look alike.
Another theory is to mean that you should say please and thank-you, and please starts with "P" and thank-you can sound like it has a "Q".
It could even relate to the amount of alcohol you have in a bar, and how well you hold your liquor and watch your drinks. In this case P's and Q's refers to pints and quarts. Then it is saying to either A) Make sure you aren't slipped something, B) Make sure you aren't stolen from or giving them all away, C) Aren't getting too drunk, or D) Aren't starting fights, being rude with girls (if you're a guy), or just in general being a mean angry drunken JA. That's the best of what I know from the many times I've asked :) Most of this knowledge is from Grandparents or Uncles by the way, so maybe biased.