from itertools import permutations
A = input().split()
print(*sorted([''.join(i) for i in list(permutations(A[0], int(A[1])))]),
    sep='\n')

efcb95ab17386a22ba6d0e8019501bb9abcb21d5
<mask token>

<mask token>
print(*sorted([''.join(i) for i in list(permutations(A[0], int(A[1])))]),
    sep='\n')

<mask token>
A = input().split()
print(*sorted([''.join(i) for i in list(permutations(A[0], int(A[1])))]),
    sep='\n')

from itertools import permutations
A = input().split()
print(*sorted([''.join(i) for i in list(permutations(A[0], int(A[1])))]),
    sep='\n')
