Generating p and q seems to work correctly.