It originates from the days when schoolchildren were taught to write their letters properly, with particular focus on the letters "p" and "q". If they weren't careful, they would often get these letters mixed up, leading to sloppy and incorrect writing.
Therefore, the idiom advises people to be mindful of their actions and words, just like a child is expected to be mindful of their letter formation.
Here are some examples of how the idiom can be used:
* "Mind your Ps and Qs when you meet the Queen."
* "Remember to mind your Ps and Qs at the job interview."
* "It's a formal dinner, so mind your Ps and Qs."