This requires you to do some data analysis. Look for patterns in the requirements. How could that data be produced with two or more nested loops?
Well, it does an A1 followed by three Bn patterns, then an A2 followed by the same Bn patterns. Now write two or more nested loops to generate that. Be as general with them as you can. Expect that the requirements could change to require an A3 series or a B4 value.