4. Find all positive integers $d$ such that there exists an integer $k \geqslant 3$, for which $d, 2d, \cdots, k d$ can be arranged in some order so that the sum of every two consecutive terms is a perfect square.
4. It is known that if the conclusion holds for $d, 2d, \cdots, kd (k \geqslant 3)$, then for the same $k$ and order, for each $d_{1}=s^{2}d$ $\left(s \in \mathbf{Z}_{+}\right)$, the conclusion also holds. Therefore, we only need to consider square-free positive integers $d$.
When $d=1, k=15$, there is the following sequence:
$$
8,1,15,10,6,3,13,12,4,5,11,14,2,7,9 \text {. }
$$

Thus, when $d$ is a perfect square, it satisfies the conditions in the problem.
Now let $d>1$. In any order, since the sum of any two consecutive terms is divisible by $d$, and $d$ is square-free, all generated perfect squares can be divided by $d^{2}$. Therefore, the problem can be restated as: find an ordering of $1,2, \cdots, k$ such that $a_{1}, a_{2}, \cdots, a_{k}$ satisfy for each $i$ $(i=1,2, \cdots, k-1)$, there exists a positive integer $q_{i}$, such that
$$
\begin{array}{l}
a_{i}+a_{i+1}=\left(d q_{i}\right)^{2} . \\
\text { Also } a_{i} \equiv-a_{i+1}(\bmod d) \text {, so } \\
a_{2 j} \equiv a_{2 l}=-a_{2 l+1} \\
\equiv-a_{2 j+1}(\bmod d)(l \in \mathbf{Z}),
\end{array}
$$

which means that the sequence modulo $d$ has only two results.
Thus, $k=2$ (contradicting $k \geqslant 3$) or $d=2$.
Notice that, $d=2$ implies that $a_{1}, a_{2}, \cdots, a_{k}$ have the same parity, which is a contradiction.
Therefore, the required $d$ is all perfect squares.