#!/usr/bin/env python3
# -*- coding: utf-8 -*-


class Card(object):

    def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

    def __str__(self):
        return str(self.card)


def print_array(a):
    print(" ".join(map(str, a)))


def bubblesort(cards, n):
    c = cards[::]
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
    return c


def selectionsort(cards, n):
    c = cards[::]
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
    return c


def main():
    n = int(input())
    cards = list(map(Card, input().split()))
    b = bubblesort(cards, n)
    print_array(b)
    print("Stable")
    s = selectionsort(cards, n)
    print_array(s)
    if b == s:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main() class Card(object):

    def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

    def __str__(self):
        return str(self.card) Card def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

     __init__ self.card = card self.card self card card self.suit = card[0] self.suit self suit card[0] card 0 self.value = int(card[1:]) self.value self value int(card[1:]) int card[1:] card 1: 1 self self card card def __str__(self):
        return str(self.card) __str__ return str(self.card) str(self.card) str self.card self card self self object def print_array(a):
    print(" ".join(map(str, a))) print_array print(" ".join(map(str, a))) print " ".join(map(str, a)) " ".join " " join map(str, a) map str a a a def bubblesort(cards, n):
    c = cards[::]
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
    return c bubblesort c = cards[::] c cards[::] cards :: for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
     i range(0, n) range 0 n for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
     j range(n - 1, i, -1) range n - 1 n 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 - 1]) c[j] c j c[j - 1] c j - 1 j 1 (c[j - 1], c[j]) c[j - 1] c j - 1 j 1 c[j] c j return c c cards cards n n def selectionsort(cards, n):
    c = cards[::]
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
    return c selectionsort c = cards[::] c cards[::] cards :: for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
     i range(0, n) range 0 n minj = i minj i for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
         j range(i, n) range i n if c[j].value < c[minj].value:
                minj = j
         c[j].value < c[minj].value c[j].value [j] c j value c[minj].value [minj] c minj value minj = j minj j (c[i], c[minj]) = (c[minj], c[i]) (c[i], c[minj]) c[i] c i c[minj] c minj (c[minj], c[i]) c[minj] c minj c[i] c i return c c cards cards n n def main():
    n = int(input())
    cards = list(map(Card, input().split()))
    b = bubblesort(cards, n)
    print_array(b)
    print("Stable")
    s = selectionsort(cards, n)
    print_array(s)
    if b == s:
        print("Stable")
    else:
        print("Not stable") main n = int(input()) n int(input()) int input() input cards = list(map(Card, input().split())) cards list(map(Card, input().split())) list map(Card, input().split()) map Card input().split() ().split () input split b = bubblesort(cards, n) b bubblesort(cards, n) bubblesort cards n print_array(b) print_array b print("Stable") print "Stable" s = selectionsort(cards, n) s selectionsort(cards, n) selectionsort cards n print_array(s) print_array s if b == s:
        print("Stable")
    else:
        print("Not stable") b == s b s print("Stable") print "Stable" print("Not stable") print "Not stable" if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def bubblesort(cards, n):
    c = cards[::]
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
    return c def bubblesort(cards, n):
    c = cards[::]
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
    return c bubblesort class Card(object):

    def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

    def __str__(self):
        return str(self.card) class Card(object):

    def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

    def __str__(self):
        return str(self.card) Card def selectionsort(cards, n):
    c = cards[::]
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
    return c def selectionsort(cards, n):
    c = cards[::]
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
    return c selectionsort def main():
    n = int(input())
    cards = list(map(Card, input().split()))
    b = bubblesort(cards, n)
    print_array(b)
    print("Stable")
    s = selectionsort(cards, n)
    print_array(s)
    if b == s:
        print("Stable")
    else:
        print("Not stable") def main():
    n = int(input())
    cards = list(map(Card, input().split()))
    b = bubblesort(cards, n)
    print_array(b)
    print("Stable")
    s = selectionsort(cards, n)
    print_array(s)
    if b == s:
        print("Stable")
    else:
        print("Not stable") main def print_array(a):
    print(" ".join(map(str, a))) def print_array(a):
    print(" ".join(map(str, a))) print_array
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


class Card(object):

    def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

    def __str__(self):
        return str(self.card)


def print_array(a):
    print(" ".join(map(str, a)))


def bubblesort(cards, n):
    c = cards[::]
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
    return c


def selectionsort(cards, n):
    c = cards[::]
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
    return c


def main():
    n = int(input())
    cards = list(map(Card, input().split()))
    b = bubblesort(cards, n)
    print_array(b)
    print("Stable")
    s = selectionsort(cards, n)
    print_array(s)
    if b == s:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main()