The initial number of inhabitants of a city of more than $150$ inhabitants is a perfect square. With an increase of $1000$ inhabitants it becomes a perfect square plus a unit. After from another increase of $1000$ inhabitants it is again a perfect square. Determine the quantity of inhabitants that are initially in the city.
1. Let the initial number of inhabitants be \( x^2 \). We are given that after an increase of 1000 inhabitants, the number of inhabitants becomes a perfect square plus one. Therefore, we can write:
   \[
   x^2 + 1000 = y^2 + 1
   \]
   Rearranging this equation, we get:
   \[
   y^2 - x^2 = 999
   \]
   This can be factored using the difference of squares:
   \[
   (y - x)(y + x) = 999
   \]
   We need to find pairs of integers \((y - x)\) and \((y + x)\) that multiply to 999.

2. The factors of 999 are:
   \[
   999 = 3^3 \times 37
   \]
   The factor pairs of 999 are:
   \[
   (1, 999), (3, 333), (9, 111), (27, 37)
   \]

3. For each factor pair \((a, b)\), we solve for \(y\) and \(x\):
   \[
   y - x = a \quad \text{and} \quad y + x = b
   \]
   Solving these equations, we get:
   \[
   y = \frac{a + b}{2} \quad \text{and} \quad x = \frac{b - a}{2}
   \]
   We need \(y\) and \(x\) to be integers, so \(a + b\) and \(b - a\) must both be even.

4. Testing the factor pairs:
   - For \((1, 999)\):
     \[
     y = \frac{1 + 999}{2} = 500, \quad x = \frac{999 - 1}{2} = 499
     \]
   - For \((3, 333)\):
     \[
     y = \frac{3 + 333}{2} = 168, \quad x = \frac{333 - 3}{2} = 165
     \]
   - For \((9, 111)\):
     \[
     y = \frac{9 + 111}{2} = 60, \quad x = \frac{111 - 9}{2} = 51
     \]
   - For \((27, 37)\):
     \[
     y = \frac{27 + 37}{2} = 32, \quad x = \frac{37 - 27}{2} = 5
     \]

5. Next, we need to check the second condition: after another increase of 1000 inhabitants, the number of inhabitants becomes a perfect square again. Therefore:
   \[
   y^2 + 1 + 1000 = z^2
   \]
   Rearranging this equation, we get:
   \[
   z^2 - y^2 = 1001
   \]
   This can be factored using the difference of squares:
   \[
   (z - y)(z + y) = 1001
   \]
   We need to find pairs of integers \((z - y)\) and \((z + y)\) that multiply to 1001.

6. The factors of 1001 are:
   \[
   1001 = 7 \times 11 \times 13
   \]
   The factor pairs of 1001 are:
   \[
   (1, 1001), (7, 143)
   \]

7. For each factor pair \((c, d)\), we solve for \(z\) and \(y\):
   \[
   z - y = c \quad \text{and} \quad z + y = d
   \]
   Solving these equations, we get:
   \[
   z = \frac{c + d}{2} \quad \text{and} \quad y = \frac{d - c}{2}
   \]
   We need \(z\) and \(y\) to be integers, so \(c + d\) and \(d - c\) must both be even.

8. Testing the factor pairs:
   - For \((1, 1001)\):
     \[
     z = \frac{1 + 1001}{2} = 501, \quad y = \frac{1001 - 1}{2} = 500
     \]
   - For \((7, 143)\):
     \[
     z = \frac{7 + 143}{2} = 75, \quad y = \frac{143 - 7}{2} = 68
     \]

9. Comparing the values of \(y\) from both sets of factor pairs, we see that \(y = 500\) is the only common value. Therefore, we have:
   \[
   x = 499
   \]
   The initial number of inhabitants is:
   \[
   x^2 = 499^2 = (500 - 1)^2 = 500^2 - 2 \cdot 500 + 1 = 250000 - 1000 + 1 = 249001
   \]

The final answer is \(\boxed{249001}\)