Rectangle $p*q,$ where $p,q$ are relatively coprime  positive integers with $p <q$ is divided into squares $1*1$.Diagonal which goes from lowest left vertice to highest right  cuts triangles from some squares.Find sum of perimeters of all such  triangles.
1. **Understanding the Problem:**
   We need to find the sum of the perimeters of all triangles formed by the diagonal of a rectangle \( p \times q \) where \( p \) and \( q \) are coprime integers and \( p < q \). The diagonal cuts through some unit squares, forming triangles.

2. **Diagonal Equation:**
   The equation of the diagonal from \((0,0)\) to \((p,q)\) is \( y = \frac{q}{p}x \).

3. **Triangles Formed:**
   The diagonal intersects the grid lines, forming right triangles. Each triangle has a base or height of 1 unit.

4. **Counting the Triangles:**
   The number of triangles formed is equal to the number of grid lines the diagonal crosses. Since \( p \) and \( q \) are coprime, the diagonal crosses \( p + q - 1 \) grid lines.

5. **Perimeter of Each Triangle:**
   Each triangle has a base or height of 1 unit. The hypotenuse of each triangle can be calculated using the Pythagorean theorem:
   \[
   \text{Hypotenuse} = \sqrt{1^2 + \left(\frac{q}{p}\right)^2} = \sqrt{1 + \left(\frac{q}{p}\right)^2}
   \]
   The perimeter of each triangle is:
   \[
   1 + 1 + \sqrt{1 + \left(\frac{q}{p}\right)^2} = 2 + \sqrt{1 + \left(\frac{q}{p}\right)^2}
   \]

6. **Sum of Perimeters:**
   The total number of triangles is \( p + q - 1 \). Therefore, the sum of the perimeters of all triangles is:
   \[
   (p + q - 1) \left( 2 + \sqrt{1 + \left(\frac{q}{p}\right)^2} \right)
   \]

7. **Simplifying the Expression:**
   Since \( \frac{q}{p} \) is a fraction, we can rewrite the expression inside the square root:
   \[
   \sqrt{1 + \left(\frac{q}{p}\right)^2} = \sqrt{\frac{p^2 + q^2}{p^2}}
   \]
   \[
   = \frac{\sqrt{p^2 + q^2}}{p}
   \]
   Therefore, the sum of the perimeters is:
   \[
   (p + q - 1) \left( 2 + \frac{\sqrt{p^2 + q^2}}{p} \right)
   \]

The final answer is \( \boxed{ (p + q - 1) \left( 2 + \frac{\sqrt{p^2 + q^2}}{p} \right) } \).