Problem

Source: Turkey EGMO TST 2017 P6

Tags: Turkey, EGMO, TST, number theory, contest problem, order of an element



Find all pairs of prime numbers $(p,q)$, such that $\frac{(2p^2-1)^q+1}{p+q}$ and $\frac{(2q^2-1)^p+1}{p+q}$ are both integers.