There are dishes, numbered from to , and types of sauce, numbered from to . Dish needs exactly two different sauces, and .
Arrange all the dishes around a circular table so that, for every sauce, all dishes that need it occupy consecutive positions around the table. This consecutive part may wrap around the end of the printed order, and it may include the entire table. A sauce that no dish needs imposes no restriction.
Several dishes may need the same pair of sauces.
Find a suitable order of the dish numbers, or report that no such order exists.
For each test case, is either if no suitable order exists, or a permutation of describing the dishes in clockwise order around the table. Any suitable order is accepted.
In the order , the dishes needing sauce form the consecutive circular part . Those needing sauce form , and those needing sauce form . Each remaining sauce is needed by one dish.
Dishes must form one consecutive part because they all need sauce . Whichever of these three dishes is in the middle has both neighboring positions occupied by the other two. However, it must also be next to dish , , or , respectively, because of its other sauce. This is impossible.
Every dish needs sauce , so its consecutive part is the entire table. The two dishes needing sauce are next to each other. Sauces and are each needed by one dish.
Sauces , , and require dishes and , dishes and , and dishes and to be adjacent, respectively. Three dishes cannot all be pairwise adjacent around a table with four dishes, so there is no suitable order.
In the shown order, the three dishes needing sauce occupy the first three positions, and the two dishes needing sauce occupy the last two positions. Every other sauce is needed by one dish.