In the first test, the stones are painted in colors $1,3,1,5,3,5$ respectively.

For the first operation, you can paint the stones at positions $4,5$ in color $1$, after which the stones will be $1,3,1,1,1,5$.

For the second operation, you can paint the stones at positions $1,2$ in color $1$. Now the stones are painted in $1,1,1,1,1,5$.

For the last operation, you can paint the last two stones in color $1$, after which all the stones will be of the same color ($1$).