# Problem: https://www.hackerrank.com/challenges/itertools-permutations/problem

from itertools import permutations

s = input().split()
str_, num_ = sorted(s[0]), int(s[1])

print (*list(map(''.join, permutations(str_, num_))), sep='\n')

45f46621575b253602dbb89ad6923d75885162f6
<mask token>

<mask token>
print(*list(map(''.join, permutations(str_, num_))), sep='\n')

<mask token>
s = input().split()
str_, num_ = sorted(s[0]), int(s[1])
print(*list(map(''.join, permutations(str_, num_))), sep='\n')

from itertools import permutations
s = input().split()
str_, num_ = sorted(s[0]), int(s[1])
print(*list(map(''.join, permutations(str_, num_))), sep='\n')

# Problem: https://www.hackerrank.com/challenges/itertools-permutations/problem

from itertools import permutations

s = input().split()
str_, num_ = sorted(s[0]), int(s[1])

print (*list(map(''.join, permutations(str_, num_))), sep='\n')
