Creating miniblocks of pairs of stimuli from same category

I have figured out how to create mini blocks of 3 repetitions with the loop function through the builder; however the problem is that once an image is selected, the same one is shown 3x rather than a new image from the same category being selected from total images list (216 images in total, 3 different image categories). I tried using the code below to ensure that a new image from the same category would be chosen (without replacement, so that an image is only shown once), but was not successful.

In the loop that I have, nReps = 3 and the selected rows is defined as $ImagesLists.pop(0)

Before Experiment Tab:

allImages = list(range(0, 216))
for i in range(0, 3):
    # Create a list of 3 randomly selected values
    newList = list(randchoice(allImages, size=3, replace=False))
    # Remove those 3 values from the list of remaining values
    for j in range(0, len(newList)):