from itertools import combinations

def g(i):

    return chr(i+96)

def f(n,i):

    global Ind

    if n==0:

        B.append("".join(A))

        return

    if n==1:

        j = Ind.pop()

        A[j] = g(i)

        B.append("".join(A))

        A[j]=0

        Ind.append(j)

        Ind = sorted(Ind)

        return

    j0 = Ind.pop(0)

    Ind1 = Ind[:]

    A[j0] = g(i)

    for k in range(n):

        for x in combinations(Ind1,n-1-k):

            tmp = []

            for j in range(n-1-k):

                A[x[j]] = g(i)

                tmp.append(x[j])

            for j in tmp:

                Ind.remove(j)

            f(k,i+1)

            for j in tmp:

                A[j] = 0

                Ind.append(j)

            Ind = sorted(Ind)

    Ind.append(j0)

    Ind = sorted(Ind)

    

N = int(eval(input()))

A = [0 for _ in range(N)]

Ind = list(range(N))

B = []

f(N,1)

B = sorted(B)

for b in B:

    print(b)
from collections import deque

D1 = {i:chr(i+96) for i in range(1,27)}

D2 = {val:key for key,val in list(D1.items())}



N = int(eval(input()))

heap = deque([(D1[1],1)])

A = []

while heap:

    a,n = heap.popleft()

    if n<N:

        imax = 0

        for i in range(len(a)):

            imax = max(imax,D2[a[i]])

        for i in range(1,min(imax+1,26)+1):

            heap.append((a+D1[i],n+1))

    if n==N:

        A.append(a)

A = sorted(list(set(A)))

for i in range(len(A)):

    print((A[i]))
from itertools import combinations


def g(i):
    return chr(i + 96)


def f(n, i):
    global Ind
    if n == 0:
        B.append("".join(A))
        return
    if n == 1:
        j = Ind.pop()
        A[j] = g(i)
        B.append("".join(A))
        A[j] = 0
        Ind.append(j)
        Ind = sorted(Ind)
        return
    j0 = Ind.pop(0)
    Ind1 = Ind[:]
    A[j0] = g(i)
    for k in range(n):
        for x in combinations(Ind1, n - 1 - k):
            tmp = []
            for j in range(n - 1 - k):
                A[x[j]] = g(i)
                tmp.append(x[j])
            for j in tmp:
                Ind.remove(j)
            f(k, i + 1)
            for j in tmp:
                A[j] = 0
                Ind.append(j)
            Ind = sorted(Ind)
    Ind.append(j0)
    Ind = sorted(Ind)


N = int(eval(input()))
A = [0 for _ in range(N)]
Ind = list(range(N))
B = []
f(N, 1)
B = sorted(B)
for b in B:
    print(b)

from collections import deque

D1 = {i: chr(i + 96) for i in range(1, 27)}
D2 = {val: key for key, val in list(D1.items())}
N = int(eval(input()))
heap = deque([(D1[1], 1)])
A = []
while heap:
    a, n = heap.popleft()
    if n < N:
        imax = 0
        for i in range(len(a)):
            imax = max(imax, D2[a[i]])
        for i in range(1, min(imax + 1, 26) + 1):
            heap.append((a + D1[i], n + 1))
    if n == N:
        A.append(a)
A = sorted(list(set(A)))
for i in range(len(A)):
    print((A[i]))

-from itertools import combinations +from collections import deque - -def g(i): -    return chr(i + 96) - - -def f(n, i): -    global Ind -    if n == 0: -        B.append("".join(A)) -        return -    if n == 1: -        j = Ind.pop() -        A[j] = g(i) -        B.append("".join(A)) -        A[j] = 0 -        Ind.append(j) -        Ind = sorted(Ind) -        return -    j0 = Ind.pop(0) -    Ind1 = Ind[:] -    A[j0] = g(i) -    for k in range(n): -        for x in combinations(Ind1, n - 1 - k): -            tmp = [] -            for j in range(n - 1 - k): -                A[x[j]] = g(i) -                tmp.append(x[j]) -            for j in tmp: -                Ind.remove(j) -            f(k, i + 1) -            for j in tmp: -                A[j] = 0 -                Ind.append(j) -            Ind = sorted(Ind) -    Ind.append(j0) -    Ind = sorted(Ind) - - +D1 = {i: chr(i + 96) for i in range(1, 27)} +D2 = {val: key for key, val in list(D1.items())} -A = [0 for _ in range(N)] -Ind = list(range(N)) -B = [] -f(N, 1) -B = sorted(B) -for b in B: -    print(b) +heap = deque([(D1[1], 1)]) +A = [] +while heap: +    a, n = heap.popleft() +    if n < N: +        imax = 0 +        for i in range(len(a)): +            imax = max(imax, D2[a[i]]) +        for i in range(1, min(imax + 1, 26) + 1): +            heap.append((a + D1[i], n + 1)) +    if n == N: +        A.append(a) +A = sorted(list(set(A))) +for i in range(len(A)): +    print((A[i]))