SP479 TPERML - Permutation generator

Description

[Wersja polska](/problems/TPERML/polski/) [English version](/problems/TPERML/english/)For each index of n element permutation print m subsequent permutations (in separate lines) in lexicographical order starting from the one pointed by index. Between outputs of subsequent tests there should be an empty line. Next permutation to the last one is the first one.

Input Format

t \[number of tests

Output Format

p1 p2 ... p(n-1) pn \[permutations\] p1 p2 ... pn p(n-1) p1 p2 ... p(n-1) pn \[permutations\] p1 p2 ... pn p(n-1)