update P and Q