#[Stax](https://github.com/tomtheisen/stax), 23 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)


[Run and debug online!](https://staxlang.xyz/#p=9ead553deb85bbdd839ac86724aa67a901a5ca7fd8cf12&i=helowi%0Amayube%0Astephens%0Aaabcdeffghij&a=1&m=2)

Takes a very long time to run. A more reasonable/feasible version is


[Run and debug online!](https://staxlang.xyz/#p=817aa4375f505a379f54504e4c26d9175c3a00cf462e8c2a0780&i=helowi%0Amayube%0Astephens%0Aaabcdeffghij&a=1&m=2)

## Explanation

Uses the unpacked version to explain.

    w                               Loop the whole program while condition is satisfied
     |N                             Next permutation (starting from the input)
       c_:=                         Index where the current array has the same element as the input (*)
           n{ch+2B}X!               Find all contiguous pairs in current string, including the pair `[last element, first element]`
                     yx!            Do the same for the input
                        |*          Outer product, contains pairs (which themselves are pairs) constructed from the last two array.
                          {   f     Only keep pairs
                           E-!      whose two elements have the same set of characters
                               +    Prepend the array at step (*).
                                    This is used as the condition for the while loop