  For a non-degenerate integral quadratic form $F(x_1, \dots , x_d)$ in
$d\geq5$ variables, we prove an optimal strong approximation theorem. Let
$\Omega$ be a fixed compact subset of the affine quadric $F(x_1,\dots,x_d)=1$
over the real numbers. Take a small ball $B$ of radius $0<r<1$ inside $\Omega$,
and an integer $m$. Further assume that $N$ is a given integer which satisfies
$N\gg_{\delta,\Omega}(r^{-1}m)^{4+\delta}$ for any $\delta>0$. Finally assume
that an integral vector $(\lambda_1, \dots, \lambda_d) $ mod $m$ is given. Then
we show that there exists an integral solution $X=(x_1,\dots,x_d)$ of $F(X)=N$
such that $x_i\equiv \lambda_i \text{ mod } m$ and $\frac{X}{\sqrt{N}}\in B$,
provided that all the local conditions are satisfied. We also show that 4 is
the best possible exponent. Moreover, for a non-degenerate integral quadratic
form in 4 variables we prove the same result if $N$ is odd and
$N\gg_{\delta,\Omega} (r^{-1}m)^{6+\epsilon}$. Based on our numerical
experiments on the diameter of LPS Ramanujan graphs and the expected square
root cancellation in a particular sum that appears in Remark~\ref{evidence}, we
conjecture that the theorem holds for any quadratic form in 4 variables with
the optimal exponent $4$.
