Step 1: Three loops, one for each direction