Find all pairs of integers $(p,q)$ for which all roots of the trinomials $x^2+px+q$ and $x^2+qx+p$ are integers.
To find all pairs of integers \((p, q)\) for which all roots of the trinomials \(x^2 + px + q\) and \(x^2 + qx + p\) are integers, we need to ensure that the discriminants of both quadratic equations are perfect squares. This is because the roots of a quadratic equation \(ax^2 + bx + c = 0\) are given by:

\[
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]

For the roots to be integers, the discriminant \(b^2 - 4ac\) must be a perfect square.

1. **Discriminant Conditions:**
   - For \(x^2 + px + q\), the discriminant is \(p^2 - 4q\).
   - For \(x^2 + qx + p\), the discriminant is \(q^2 - 4p\).

   Therefore, we need:
   \[
   p^2 - 4q = a^2 \quad \text{and} \quad q^2 - 4p = b^2
   \]
   for some integers \(a\) and \(b\).

2. **Case Analysis:**

   - **Case 1: \(p > q + 1\)**
     \[
     p^2 - 4q = a^2 \quad \Rightarrow \quad a^2 = p^2 - 4q > (p - 2)^2 \quad \Rightarrow \quad a > p - 2
     \]
     \[
     4q = (p - a)(p + a)
     \]
     Since \(p + a > 2q\), we assume \(p + a = 4q\) and \(p - a = 1\). Solving these:
     \[
     p + a = 4q \quad \text{and} \quad p - a = 1
     \]
     Adding these equations:
     \[
     2p = 4q + 1 \quad \Rightarrow \quad p = 2q + \frac{1}{2}
     \]
     This is not possible since \(p\) and \(q\) are integers. Hence, this case is false.

   - **Case 2: \(p = q + 1\)**
     \[
     q^2 - 4p = (q + 1)^2 - 4(q + 1) = q^2 + 2q + 1 - 4q - 4 = q^2 - 2q - 3
     \]
     \[
     q^2 - 2q - 3 = b^2
     \]
     This can be rewritten as:
     \[
     (q - 3)(q + 1) = b^2
     \]
     We need \(q - 3\) and \(q + 1\) to be perfect squares. Let \(q - 3 = k^2\) and \(q + 1 = m^2\):
     \[
     m^2 - k^2 = 4 \quad \Rightarrow \quad (m - k)(m + k) = 4
     \]
     Possible pairs \((m, k)\) are \((3, 1)\) and \((2, 0)\):
     - For \((m, k) = (3, 1)\):
       \[
       q + 1 = 9 \quad \Rightarrow \quad q = 8 \quad \Rightarrow \quad p = q + 1 = 9
       \]
     - For \((m, k) = (2, 0)\):
       \[
       q + 1 = 4 \quad \Rightarrow \quad q = 3 \quad \Rightarrow \quad p = q + 1 = 4
       \]

   - **Case 3: \(p = q\)**
     \[
     p^2 - 4p = a^2 \quad \Rightarrow \quad p(p - 4) = a^2
     \]
     We need \(p(p - 4)\) to be a perfect square. Let \(p = 4\):
     \[
     4(4 - 4) = 0 \quad \Rightarrow \quad a = 0
     \]
     Thus, \(p = q = 4\).

3. **Conclusion:**
   The valid pairs \((p, q)\) are:
   \[
   (4, 4), (9, 8), (8, 9)
   \]

The final answer is \(\boxed{(4, 4), (9, 8), (8, 9)}\).