A2 and A4 test reorganized using a foreach loop