Substituting P = 0,1,2,3,4,5 in turn in the given equation, it follows that: (P, Q) = (3,1), (5,3) are the only solutions whenever P ≤ 5.
If possible, we suppose that valid solutions exist for P > 5. In that situation, 3^Q + 5 is divisible by 2^6 = 64. On the other hand, 3^16 = 1 mod 64, and we observe that: 3^11 =  5 mod 64, and 3 ^k ≠ 5 mod 64 for other values of k from 0 to 15.
Accordingly, Q must be of the form: Q = 16k + 11.
Now, by Fermat’s Little Theorem, we have: 3^16 = 1 mod 17, so that: 3 ^(16k+11) = 3^11 = 7 mod 17.
Accordingly, 2^P = 3^11 + 5 = 12 mod 17.
However, the valid residues of 2^P, in mod 17 are 2, 4, 8, 16, 15, 13, 9, 1, and therefore we cannot have: 2^P = 12 mod 17. This contradicts our supposition that there are valid solutions whenever P > 5.
Consequently, (P, Q) = (3,1), (5,3) are the only possible nonnegative solutions to the given problem.
