P-algebras and Q-algebras