How can I loop options to display variants as cards in rows?

Suppose we have three options suppose A B and C. A has 5 values a1 a2 a3 a4 and a5, B has values b1 and b2, C has values c1 c2 c3 c4 c5. And the variants will be like a1/b1/c1, a1/b1/c2, a1/b1/c3, a1/b1/c4, a1/b1/c5 then it will go for a1/b2/c1, a1/b2/c2, a1/b2/c3… like that, our need is for every A values (a1,a2,a3,a4,a5) we want to show variants as cards down by down like the a1 contained variants(a1/b1/c1, a1/b1/c2, a1/b1/c3, a1/b1/c4, a1/b1/c5 and a1/b2/c1, a1/b2/c2, a1/b2/c3… ) as cards in one row, then the a2 contained variants as cards in second row, like that…so the question is how can we loop the options so that we could get the variants in this manner…? It’s an urgent requirement please help