def leng(s): a = [] for i in s: l = len(i) a.append(l) # print(a) return a def str_sort(s): flag = True a = leng(s) while flag: flag = False for i in range(1, len(a)): if a[i-1] > a[i]: a[i-1], a[i] = a[i], a[i-1] s[i-1], s[i] = s[i], s[i-1] flag = True return s while True: try: arr = [] n = int(input()) for i in range(n): a = input() if a == 'stop': break arr.append(a) res = str_sort(arr) res = '\n'.join(res) print(res) except: break