I propose that you create a function that, when supplied with i and n, yields a string that corresponds to line i of card n. To obtain the desired result, you may then run that in a double nested loop, publishing the outcomes sequentially. To begin, you can create a model of the desired output to serve as a guide while you code the loop.