Nuclear spin dynamics influenced and detected by electron spin polarization in CdTe/(Cd,Mg)Te quantum wells