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


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

Thanks for @recursive for saving 2 bytes.

Takes a very long time to run. A more reasonable/feasible version is (just 2 bytes longer)


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

## Explanation

Uses the unpacked version to explain.

    w                            Loop anything before `}` while
     |N                          Next permutation (starting from the input)
       c_:=                      Index where the current array has the same element as the input (*)
                       }ch+2B    Define a block that finds all contiguous pairs in current string, including the pair `[last element, first element]`
           nG                    Apply the defined block to current string                         
             yG                  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