solve P31 and P32