“unsort” an array in Excel

I have two dynamic Arrays as shown below (first picture), the first array (the first column) consists of number from 1 to x (in this case 5), which all get repeated the same amount (in this case 3 times). The second array (second and third column) consists of permutations from 1 to y (in this case 6), without taking into account doublettes (e.g. 1-1, 2-2 etc) as well as the order doesnt matter (e.g. there won’t be a 2-1 as there already is a 1-2).

How can I arrange the second array, so that no number appears more than once per number of the first array?
E.g. in the first row (first array 1, second array 1-2) means we can’t have either 1 or 2 in the second array for every following row that has a 1 in the first array.
A “unsorted” array could be for example as shown in the second picture (manually written without formulas).