from collections import namedtuple
Card = namedtuple('Card', 'suit value')

def BubbleSort(C):
    for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j]

def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i]

def checkStable(C0, C1):
    result = True
    for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
    return result

if __name__=='__main__':
    N = int(input()) 
    Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split())))
    Cb,Cs = [Co[:] for _ in range(2)]
    for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]):
        Sort(C)
        print(*["".join([X.suit,str(X.value)]) for X in C])
        print("Stable" if checkStable(Co,C) else "Not stable") from collections import namedtuple Card = namedtuple('Card', 'suit value') Card namedtuple('Card', 'suit value') namedtuple 'Card' 'suit value' def BubbleSort(C):
    for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j] BubbleSort for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j] i range(len(C)) range len(C) len C for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j] j range(len(C)-1,i,-1) range len(C)-1 len(C) len C 1 i -1 if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j] C[j].value < C[j-1].value C[j].value [j] C j value C[j-1].value [j-1] C j-1 j 1 value C[j],C[j-1] = C[j-1],C[j] C[j] C j C[j-1] C j-1 j 1 C[j-1] C j-1 j 1 C[j] C j C C def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i] SelectionSort for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i] i range(len(C)) range len(C) len C mini = i mini i for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
         j range(i,len(C)) range i len(C) len C if C[j].value < C[mini].value:
                mini = j
         C[j].value < C[mini].value C[j].value [j] C j value C[mini].value [mini] C mini value mini = j mini j C[i],C[mini] = C[mini],C[i] C[i] C i C[mini] C mini C[mini] C mini C[i] C i C C def checkStable(C0, C1):
    result = True
    for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
    return result checkStable result = True result True for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
     i range(1,10) range 1 10 x.suit for x in list(filter(lambda c: c.value==i,C0)) for x in list(filter(lambda c: c.value==i,C0)) x list(filter(lambda c: c.value==i,C0)) list filter(lambda c: c.value==i,C0) filter lambda c: c.value==i c.value==i c.value c value i c C0 for x in list(filter(lambda c: c.value==i,C0)) x.suit x suit f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))] f0 [x.suit for x in list(filter(lambda c: c.value==i,C0))] x.suit for x in list(filter(lambda c: c.value==i,C1)) for x in list(filter(lambda c: c.value==i,C1)) x list(filter(lambda c: c.value==i,C1)) list filter(lambda c: c.value==i,C1) filter lambda c: c.value==i c.value==i c.value c value i c C1 for x in list(filter(lambda c: c.value==i,C1)) x.suit x suit f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))] f1 [x.suit for x in list(filter(lambda c: c.value==i,C1))] if f0!=f1:
            result = False
     f0!=f1 f0 f1 result = False result False return result result C0 C0 C1 C1 if __name__=='__main__':
    N = int(input()) 
    Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split())))
    Cb,Cs = [Co[:] for _ in range(2)]
    for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]):
        Sort(C)
        print(*["".join([X.suit,str(X.value)]) for X in C])
        print("Stable" if checkStable(Co,C) else "Not stable") __name__=='__main__' __name__ '__main__' N = int(input()) N int(input()) int input() input Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split()))) Co list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split()))) list map(lambda X: Card(X[0],int(X[1])), map(list, input().split())) map lambda X: Card(X[0],int(X[1])) Card(X[0],int(X[1])) Card X[0] X 0 int(X[1]) int X[1] X 1 X map(list, input().split()) map list input().split() ().split () input split Co[:] for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) Co[:] Co : Cb,Cs = [Co[:] for _ in range(2)] Cb [Co[:] for _ in range(2)] Cs for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]):
        Sort(C)
        print(*["".join([X.suit,str(X.value)]) for X in C])
        print("Stable" if checkStable(Co,C) else "Not stable") C Sort zip([Cb,Cs], [BubbleSort, SelectionSort]) zip [Cb,Cs] Cb Cs [BubbleSort, SelectionSort] BubbleSort SelectionSort Sort(C) Sort C "".join([X.suit,str(X.value)]) for X in C for X in C X C for X in C "".join([X.suit,str(X.value)]) "".join "" join [X.suit,str(X.value)] X.suit X suit str(X.value) str X.value X value print(*["".join([X.suit,str(X.value)]) for X in C]) print *["".join([X.suit,str(X.value)]) for X in C] ["".join([X.suit,str(X.value)]) for X in C] print("Stable" if checkStable(Co,C) else "Not stable") print "Stable" if checkStable(Co,C) else "Not stable" checkStable(Co,C) checkStable Co C "Stable" "Not stable" Card = namedtuple('Card', 'suit value') namedtuple('Card', 'suit value') Card N = int(input()) int(input()) N def checkStable(C0, C1):
    result = True
    for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
    return result def checkStable(C0, C1):
    result = True
    for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
    return result checkStable Cs = [Co[:] for _ in range(2)] [Co[:] for _ in range(2)] Cs def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i] def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i] SelectionSort Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split()))) list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split()))) Co def BubbleSort(C):
    for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j] def BubbleSort(C):
    for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j] BubbleSort Cb,Cs = [Co[:] for _ in range(2)] [Co[:] for _ in range(2)] Cb
from collections import namedtuple
Card = namedtuple('Card', 'suit value')

def BubbleSort(C):
    for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j]

def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i]

def checkStable(C0, C1):
    result = True
    for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
    return result

if __name__=='__main__':
    N = int(input()) 
    Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split())))
    Cb,Cs = [Co[:] for _ in range(2)]
    for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]):
        Sort(C)
        print(*["".join([X.suit,str(X.value)]) for X in C])
        print("Stable" if checkStable(Co,C) else "Not stable")