N = int(input())
C = input().split()
_C = C.copy()

for i in range(N):
    for j in range(N-1, i, -1):
        if (C[j][1] < C[j-1][1]):
            C[j], C[j-1] = C[j-1], C[j]
print(*C)
print("Stable")

for i in range(N):
    m = i
    for j in range(i, N):
        if (_C[j][1] < _C[m][1]):
            m = j
    _C[i], _C[m] = _C[m], _C[i]
print(*_C)
if(C ==_C):
    print("Stable")
else:
    print("Not stable") N = int(input()) N int(input()) int input() input C = input().split() C input().split() ().split () input split _C = C.copy() _C C.copy() C.copy C copy for i in range(N):
    for j in range(N-1, i, -1):
        if (C[j][1] < C[j-1][1]):
            C[j], C[j-1] = C[j-1], C[j] i range(N) range N for j in range(N-1, i, -1):
        if (C[j][1] < C[j-1][1]):
            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][1] < C[j-1][1]):
            C[j], C[j-1] = C[j-1], C[j] C[j][1] < C[j-1][1] C[j][1] [j] C j 1 C[j-1][1] [j-1] C j-1 j 1 1 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 print(*C) print *C C print("Stable") print "Stable" for i in range(N):
    m = i
    for j in range(i, N):
        if (_C[j][1] < _C[m][1]):
            m = j
    _C[i], _C[m] = _C[m], _C[i] i range(N) range N m = i m i for j in range(i, N):
        if (_C[j][1] < _C[m][1]):
            m = j
     j range(i, N) range i N if (_C[j][1] < _C[m][1]):
            m = j
     _C[j][1] < _C[m][1] _C[j][1] [j] _C j 1 _C[m][1] [m] _C m 1 m = j m j _C[i], _C[m] = _C[m], _C[i] _C[i] _C i _C[m] _C m _C[m] _C m _C[i] _C i print(*_C) print *_C _C if(C ==_C):
    print("Stable")
else:
    print("Not stable") C ==_C C _C print("Stable") print "Stable" print("Not stable") print "Not stable" N = int(input()) int(input()) N m = i i m m = j j m C = input().split() input().split() C _C = C.copy() C.copy() _C
N = int(input())
C = input().split()
_C = C.copy()

for i in range(N):
    for j in range(N-1, i, -1):
        if (C[j][1] < C[j-1][1]):
            C[j], C[j-1] = C[j-1], C[j]
print(*C)
print("Stable")

for i in range(N):
    m = i
    for j in range(i, N):
        if (_C[j][1] < _C[m][1]):
            m = j
    _C[i], _C[m] = _C[m], _C[i]
print(*_C)
if(C ==_C):
    print("Stable")
else:
    print("Not stable")