Updating p and q and increasing Main