Here's some issues to start with ...
Should you be adding a ";" after each ADD command?
Also, ensure your variable names from S6 are correct. Make sure they actually exist.
Have you also defined all the necessary codes 1-16 in your parent list S6RowList?
To lighten the load on your script, you could use a for loop (see below) ...
Begin Unverified Perl
for($i=4; $i<=16; $i++)
Let me know how you go.