Let $ M$ be the intersection of the diagonals of a convex quadrilateral $ ABCD$. Determine all such quadrilaterals for which there exists a line $ g$ that passes through $ M$ and intersects the side $ AB$ in $ P$ and the side $ CD$ in $ Q$, such that the four triangles $ APM$, $ BPM$, $ CQM$, $ DQM$ are similar.
1. **Identify the given conditions and setup:**
   - Let \( M \) be the intersection of the diagonals \( AC \) and \( BD \) of the convex quadrilateral \( ABCD \).
   - There exists a line \( g \) passing through \( M \) that intersects \( AB \) at \( P \) and \( CD \) at \( Q \).
   - The triangles \( \triangle APM \), \( \triangle BPM \), \( \triangle CQM \), and \( \triangle DQM \) are similar.

2. **Analyze the similarity conditions:**
   - Since \( \triangle APM \sim \triangle BPM \), the corresponding angles must be equal:
     \[
     \angle APM = \angle BPM \quad \text{and} \quad \angle PAM = \angle PBM
     \]
   - Similarly, for \( \triangle CQM \sim \triangle DQM \):
     \[
     \angle CQM = \angle DQM \quad \text{and} \quad \angle QCM = \angle QDM
     \]

3. **Implications of angle equalities:**
   - From \( \angle APM = \angle BPM \), it follows that \( P \) lies on the angle bisector of \( \angle AMB \).
   - From \( \angle CQM = \angle DQM \), it follows that \( Q \) lies on the angle bisector of \( \angle CMD \).

4. **Consider the properties of the quadrilateral:**
   - Since \( M \) is the intersection of the diagonals, \( M \) is the midpoint of both diagonals if the quadrilateral is a parallelogram.
   - For the triangles to be similar, the angles at \( M \) must be equal, implying that the diagonals bisect each other at right angles.

5. **Conclusion about the quadrilateral:**
   - The only quadrilateral where the diagonals bisect each other at right angles and the triangles formed by the diagonals and sides are similar is a square.
   - In a square, the diagonals are equal and bisect each other at right angles, ensuring the similarity of the triangles.

\[
\boxed{\text{The quadrilateral must be a square.}}
\]