Initial array state: x={1,2,3,4,5,6,7,8}.
For i=2, x[x[2]]=x[3]=x[2]=3, so the array becomes {1,2,3,3,5,6,7,8}.
For i=3, x[x[3]]=x[3]=x[3]=3, so the array remains {1,2,3,3,5,6,7,8}.
For i=4, x[x[4]]=x[5]=x[4]=5, so the array becomes {1,2,3,3,5,5,7,8}.
For i=5, x[x[5]]=x[5]=x[5]=5, so the array remains {1,2,3,3,5,5,7,8}.
The final loop prints the elements of x as 12335578.