Step 1: Use the condition that the parabola passes through \( (1,-1) \).
Given parabola is:
\[
y=x^2+px+q
\]
Since it passes through the point \( (1,-1) \), substitute \( x=1 \) and \( y=-1 \):
\[
-1=1+p+q
\]
\[
p+q=-2
\]
So, we get:
\[
q=-2-p
\]
Step 2: Find the y-coordinate of the vertex.
For the parabola \( y=x^2+px+q \), the x-coordinate of the vertex is:
\[
x_v=-\frac{p}{2}
\]
Now substitute this into the parabola to get the y-coordinate of the vertex:
\[
y_v=\left(-\frac{p}{2}\right)^2+p\left(-\frac{p}{2}\right)+q
\]
\[
y_v=\frac{p^2}{4}-\frac{p^2}{2}+q
\]
\[
y_v=q-\frac{p^2}{4}
\]
Using \( q=-2-p \), we get:
\[
y_v=-2-p-\frac{p^2}{4}
\]
Step 3: Use the condition of minimum distance from x-axis.
The distance of the vertex from the x-axis is \( |y_v| \). For minimum distance, this value must be minimum. Since the minimum possible value of an absolute quantity is 0, we set:
\[
y_v=0
\]
Thus:
\[
-2-p-\frac{p^2}{4}=0
\]
Multiply by 4 throughout:
\[
-8-4p-p^2=0
\]
\[
p^2+4p+8=0
\]
Actually, rewrite carefully from the vertex form condition using the parabola relation:
\[
y_v=q-\frac{p^2}{4}
\]
and for minimum distance from x-axis, vertex lies on x-axis, so:
\[
q-\frac{p^2}{4}=0
\]
Hence:
\[
q=\frac{p^2}{4}
\]
Now using \( p+q=-2 \):
\[
p+\frac{p^2}{4}=-2
\]
Multiply by 4:
\[
p^2+4p+8=0
\]
This gives no real value, so now use the idea that the vertex distance is minimum under the constraint \( q=-2-p \). Define:
\[
f(p)=q-\frac{p^2}{4}=-2-p-\frac{p^2}{4}
\]
Distance is minimum when the vertex is nearest to x-axis, so the quadratic expression must attain its greatest possible value because it is always negative. Differentiate:
\[
f'(p)=-1-\frac{p}{2}
\]
Set \( f'(p)=0 \):
\[
-1-\frac{p}{2}=0
\]
\[
p=-2
\]
Then:
\[
q=-2-(-2)=0
\]
Step 4: Calculate \( p^2+q^2 \).
Now:
\[
p=-2,\qquad q=0
\]
Therefore:
\[
p^2+q^2=(-2)^2+0^2
\]
\[
=4
\]
Step 5: Conclusion.
Hence, the required value of \( p^2+q^2 \) is \( 4 \).
Final Answer: \( 4 \)