def is_stable(oline, line):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
    return True

N = int(input())
line = input().split()
oline = line.copy()
#BubbleSort
for i in range(N):
    for j in range(N-1, i, -1):
        if int(line[j][1]) < int(line[j-1][1]):
            tmp = line[j]
            line[j] = line[j-1]
            line[j-1] = tmp
print(' '.join(line))
print(('Not stable', 'Stable')[is_stable(oline, line)])

#SelectionSort
line = oline.copy()
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if int(line[minj][1]) > int(line[j][1]):
            minj = j
    tmp = line[i]
    line[i] = line[minj]
    line[minj] = tmp
print(' '.join(line))

print(('Not stable', 'Stable')[is_stable(oline, line)]) def is_stable(oline, line):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
    return True is_stable for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
     i range(N) range N for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
     j range(i+1, N) range i+1 i 1 N for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
     a range(N) range N for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
     b range(a+1, N) range a+1 a 1 N if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
     (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]) (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) oline[i][1] == oline[j][1] oline[i][1] [i] oline i 1 oline[j][1] [j] oline j 1 oline[i] == line[b] oline[i] oline i line[b] line b oline[j] == line[a] oline[j] oline j line[a] line a return False False return True True oline oline line line N = int(input()) N int(input()) int input() input line = input().split() line input().split() ().split () input split oline = line.copy() oline line.copy() line.copy line copy for i in range(N):
    for j in range(N-1, i, -1):
        if int(line[j][1]) < int(line[j-1][1]):
            tmp = line[j]
            line[j] = line[j-1]
            line[j-1] = tmp i range(N) range N for j in range(N-1, i, -1):
        if int(line[j][1]) < int(line[j-1][1]):
            tmp = line[j]
            line[j] = line[j-1]
            line[j-1] = tmp j range(N-1, i, -1) range N-1 N 1 i -1 if int(line[j][1]) < int(line[j-1][1]):
            tmp = line[j]
            line[j] = line[j-1]
            line[j-1] = tmp int(line[j][1]) < int(line[j-1][1]) int(line[j][1]) int line[j][1] [j] line j 1 int(line[j-1][1]) int line[j-1][1] [j-1] line j-1 j 1 1 tmp = line[j] tmp line[j] line j line[j] = line[j-1] line[j] line j line[j-1] line j-1 j 1 line[j-1] = tmp line[j-1] line j-1 j 1 tmp print(' '.join(line)) print ' '.join(line) ' '.join ' ' join line print(('Not stable', 'Stable')[is_stable(oline, line)]) print ('Not stable', 'Stable')[is_stable(oline, line)] ('Not stable', 'Stable') 'Not stable' 'Stable' is_stable(oline, line) is_stable oline line line = oline.copy() line oline.copy() oline.copy oline copy for i in range(N):
    minj = i
    for j in range(i+1, N):
        if int(line[minj][1]) > int(line[j][1]):
            minj = j
    tmp = line[i]
    line[i] = line[minj]
    line[minj] = tmp i range(N) range N minj = i minj i for j in range(i+1, N):
        if int(line[minj][1]) > int(line[j][1]):
            minj = j
     j range(i+1, N) range i+1 i 1 N if int(line[minj][1]) > int(line[j][1]):
            minj = j
     int(line[minj][1]) > int(line[j][1]) int(line[minj][1]) int line[minj][1] [minj] line minj 1 int(line[j][1]) int line[j][1] [j] line j 1 minj = j minj j tmp = line[i] tmp line[i] line i line[i] = line[minj] line[i] line i line[minj] line minj line[minj] = tmp line[minj] line minj tmp print(' '.join(line)) print ' '.join(line) ' '.join ' ' join line print(('Not stable', 'Stable')[is_stable(oline, line)]) print ('Not stable', 'Stable')[is_stable(oline, line)] ('Not stable', 'Stable') 'Not stable' 'Stable' is_stable(oline, line) is_stable oline line minj = j j minj minj = i i minj oline = line.copy() line.copy() oline line = input().split() input().split() line line = oline.copy() oline.copy() line tmp = line[j] line[j] tmp tmp = line[i] line[i] tmp def is_stable(oline, line):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
    return True def is_stable(oline, line):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
    return True is_stable N = int(input()) int(input()) N
def is_stable(oline, line):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
                        return False
    return True

N = int(input())
line = input().split()
oline = line.copy()
#BubbleSort
for i in range(N):
    for j in range(N-1, i, -1):
        if int(line[j][1]) < int(line[j-1][1]):
            tmp = line[j]
            line[j] = line[j-1]
            line[j-1] = tmp
print(' '.join(line))
print(('Not stable', 'Stable')[is_stable(oline, line)])

#SelectionSort
line = oline.copy()
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if int(line[minj][1]) > int(line[j][1]):
            minj = j
    tmp = line[i]
    line[i] = line[minj]
    line[minj] = tmp
print(' '.join(line))

print(('Not stable', 'Stable')[is_stable(oline, line)])