Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.

The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).

Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of hashtags being edited now.

Each of the next n lines contains exactly one hashtag of positive length.

It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.


-----Output-----

Print the resulting hashtags in any of the optimal solutions.


-----Examples-----
Input
3
#book
#bigtown
#big

Output
#b
#big
#big

Input
3
#book
#cool
#cold

Output
#book
#co
#cold

Input
4
#car
#cart
#art
#at

Output
#
#
#art
#at

Input
3
#apple
#apple
#fruit

Output
#apple
#apple
#fruit



-----Note-----

Word a_1, a_2, ..., a_{m} of length m is lexicographically not greater than word b_1, b_2, ..., b_{k} of length k, if one of two conditions hold:   at first position i, such that a_{i} ≠ b_{i}, the character a_{i} goes earlier in the alphabet than character b_{i}, i.e. a has smaller character than b in the first position where they differ;  if there is no such position i and m ≤ k, i.e. the first word is a prefix of the second or two words are equal. 

The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.

For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.

According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.

Difficulty: interview

Starter code:

Solutions:
def sortHashtags(htags):
	def shorten(j, i):
		s = 0
		while s < len(htags[i]) and htags[i][s] == htags[j][s]:
			s += 1
		htags[j] = htags[j][:s]

	n = len(htags)


	for i in range(n-1, 0, -1):
		if htags[i-1] > htags[i]:
			shorten(i-1, i)

	return '\n'.join(htags)

n = int(input())
tags = []
for i in range(n):
	tags.append(input())

print(sortHashtags(tags))


from sys import stdin,stdout
n=int(stdin.readline())
A = [0] * n
for j in range(n):
    A[j] = stdin.readline().strip()
answer = [0] * n
answer[-1] = A[-1]
for j in range(n-2,-1,-1):
    if A[j] <= answer[j+1]:
        answer[j] = A[j]
    else:
        for i in range(min(len(answer[j+1]),len(A[j]))):
            if A[j][i] > answer[j+1][i]:
                i-=1
                break
        answer[j] = A[j][:i+1]
print('\n'.join(answer))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    a = [S() for _ in range(n)]
    for i in range(n-2,-1,-1):
        t = a[i]
        s = a[i+1]
        sl = len(s)
        for j in range(1,len(t)):
            if j >= sl:
                a[i] = s
                break
            if t[j] > s[j]:
                a[i] = t[:j]
                break
            if t[j] < s[j]:
                break

    print('\n'.join(a))

main()

#!/usr/bin/env python3
from sys import stdin,stdout

def ri():
    return list(map(int, input().split()))

#n=int(stdin.readline())
n = int(input())

s =[]
for i in range(n):
   # s.append(input())
    s.append(stdin.readline().strip())

for i in range(n-1, 0, -1):
    mind = min(len(s[i]), len(s[i-1]))
    for j in range(mind):
        if s[i-1][j] < s[i][j]:
            break
        elif s[i-1][j] == s[i][j]:
            if j+1 == mind:
                s[i-1] = s[i-1][:mind]
                break
            continue
        else:
            s[i-1] = s[i-1][:j]
            break
#for i in range(n):
#    print(s[i])
print('\n'.join(s))



#!/usr/bin/env python3
from sys import stdin,stdout

def ri():
    return list(map(int, input().split()))

#n=int(stdin.readline())
n = int(input())

s =[]
for i in range(n):
    #s.append(input())
    s.append(stdin.readline().strip())

for i in range(n-1, 0, -1):
    if s[i-1] <= s[i]:
        continue
    else:
        mind = min(len(s[i]), len(s[i-1]))
        for j in range(mind):
            if s[i-1][j] > s[i][j]:
                s[i-1] = s[i-1][:j]
                break
        else:
            s[i-1] = s[i-1][:mind]

#for i in range(n):
#    print(s[i])
print('\n'.join(s))



def g(c,d):
    s=0
    while s<len(a[d]) and a[c][s]==a[d][s]:s+=1
    a[c]=a[c][:s]

def f(a):
    for i in range(len(a)-1,0,-1):
        if a[i-1]>a[i]:g(i-1,i)
    print('\n'.join(a))

n=int(input())
a=[input()for i in range(n)]
f(a)




# Description of the problem can be found at http://codeforces.com/problemset/problem/777/D

num = int(input())
hts = list(input() for _ in range(num))

i = num - 2
while i >= 0:
    if hts[i] > hts[i + 1]:
        n = 1
        while n < len(hts[i + 1]) and hts[i][n] == hts[i + 1][n]: 
            n += 1
        hts[i] = hts[i][:n]
    i -= 1
    
print("\n".join(hts))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    a = [S() for _ in range(n)]
    for i in range(n-2,-1,-1):
        t = a[i]
        s = a[i+1]
        sl = len(s)
        for j in range(1,len(t)):
            if j >= sl:
                a[i] = s
                break
            if t[j] > s[j]:
                a[i] = t[:j]
                break
            if t[j] < s[j]:
                break

    return '\n'.join(a)

print(main())

n = int(input())
arr = [input() for i in range(n)]

for i in range(n-1,0,-1):
	new = arr[i]
	old = arr[i-1]
	le1 = len(new)
	le2 = len(old)
	for j in range(min(le1,le2)):
		if new[j]<old[j]:
			arr[i-1] = old[:j]
			break
		elif new[j]>old[j]: break
	else:
		if le2>le1:
			arr[i-1] = arr[i]


print('\n'.join(arr))


n = int(input())
l = []
for i in range(n):
    l.append(input())
def lexi(i):
    j = 1
    while j < len(l[i]) and l[i-1][j] == l[i][j]:
        j += 1
    l[i - 1] = l[i - 1][:j]           
for i in range(n - 1, 0, -1):
    if l[i - 1] > l[i]:
        lexi(i)
print("\n".join(l))

n = int(input())
l = []
for i in range(n):
    l.append(input())
    
def lexi(i):
    j = 1
    while j < len(l[i]) and l[i-1][j] == l[i][j]:
        j += 1
    l[i - 1] = l[i - 1][:j] 
              
for i in range(n - 1, 0, -1):
    if l[i - 1] > l[i]:
        j = 1
        while j < len(l[i]) and l[i-1][j] == l[i][j]:
            j += 1
        l[i - 1] = l[i - 1][:j] 
print("\n".join(l))

n = int(input())

inp = [0] * n

for i in range(n):
	inp[i] = input()
	
def common_str(a, b):
	l = 1
	for i in range(1, len(a)):
		if a[i] != b[i]:
			break
		l += 1
		
	return a[:l]
	
for i in range(n - 1, 0, -1):
	if inp[i] < inp[i - 1]:
		inp[i - 1] = common_str(inp[i], inp[i - 1])
	
print('\n'.join(inp))
	

	


N = int( input() )
A = [ input() for i in range( N ) ]
for i in range( N - 1, 0, -1 ):
  if A[ i - 1 ] > A[ i ]:
    ptr = 0
    while ptr < len( A[ i ] ) and A[ i - 1 ][ ptr ] == A[ i ][ ptr ]:
      ptr += 1
    A[ i - 1 ] = A[ i - 1 ][ : ptr ]
print( '\n'.join( A ) )


def g(c,d):
    s=0
    while s<len(a[d]) and a[c][s]==a[d][s]:s+=1
    a[c]=a[c][:s]

def f(a):
    for i in range(len(a)-1,0,-1):
        if a[i-1]>a[i]:g(i-1,i)
    print('\n'.join(a))

n=int(input())
a=[input()for i in range(n)]
f(a)

def cut_to_lexicographic(word_bigger, word_smaller):
    for l in range(len(word_bigger)):
        if word_bigger[l] != word_smaller[l]:
            return word_bigger[:l]
    return word_bigger


n = int(input())
array = [str(input()) for c in range(n)]

b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        if len(array[b]) > len(array[b + 1]):
            array[b] = array[b][:len(array[b + 1])]
        array[b] = cut_to_lexicographic(array[b+1], array[b])
print("\n".join(array))

def cut_to_lexicographic(word_bigger, word_smaller):
    for l in range(len(word_bigger)):
        if word_bigger[l] != word_smaller[l]:
            return word_bigger[:l]
    return word_bigger


n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        if len(array[b]) > len(array[b + 1]):
            array[b] = array[b][:len(array[b + 1])]
        array[b] = cut_to_lexicographic(array[b], array[b+1])
print("\n".join(array))

def cut_to_lexicographic(word_bigger, word_smaller):
    if word_bigger <= word_smaller:
        return word_bigger
    for l in range(len(word_bigger)):
        if word_bigger[l] != word_smaller[l]:
            return word_bigger[:l]
    return word_bigger

n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        if len(array[b]) > len(array[b + 1]):
            array[b] = array[b][:len(array[b + 1])]
        array[b] = cut_to_lexicographic(array[b], array[b+1])
print("\n".join(array))

def cut_to_lexicographic(word_bigger, word_smaller):
    if len(word_bigger) > len(word_smaller):
        return word_bigger[:len(word_smaller)]
    for l in range(len(word_bigger)):
        if word_bigger[l] != word_smaller[l]:
            return word_smaller[:l]
    return word_bigger


n = int(input())
array = [str(input()) for c in range(n)]

b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        array[b] = cut_to_lexicographic(array[b], array[b+1])
print("\n".join(array))

def cut_to_lexicographic(word_bigger, word_smaller):
    for l in range(len(word_bigger[:len(word_smaller)])):
        if word_bigger[l] != word_smaller[l]:
            return word_smaller[:l]
    return word_bigger[:len(word_smaller)]


n = int(input())
array = [str(input()) for c in range(n)]

b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        array[b] = cut_to_lexicographic(array[b], array[b+1])
print("\n".join(array))

def sorting(string, string1):
    if len(string) > len(string1):
        string = string[:len(string1)]
    for q in range(len(string)):
        if string[q] > string1[q]:
            string = string[:q]
            break
    return string
n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        array[b] = sorting(array[b], array[b + 1])
print("\n".join(array))

import sys
n = int(sys.stdin.readline().strip())
ss = [sys.stdin.readline().strip() for _ in range(n)]

# def compare_and_truncate(s1, s2):
#     if s1 == s2:
#         return s1
#     min_l = min(len(s1), len(s2))
#     for i in range(min_l):
#         if ord(s1[i]) < ord(s2[i]):
#             return s1
#         elif ord(s1[i]) > ord(s2[i]):
#             return s1[:i]
#     return s1[:min_l]

def compare_and_truncate(s1,s2):
    if s1 > s2:
        i = 0
        while i < len(s2) and s1[i] == s2[i]:
            i += 1
        return s1[:i]
    return s1



for i in range(len(ss)-2,-1,-1):
    ss[i] = compare_and_truncate(ss[i],ss[i+1])

ans = ""
for s in ss:
    ans += s + "\n"

sys.stdout.write(ans)


n = int(input())
ss = [input().strip() for _ in range(n)]

# def compare_and_truncate(s1, s2):
#     if s1 == s2:
#         return s1
#     min_l = min(len(s1), len(s2))
#     for i in range(min_l):
#         if ord(s1[i]) < ord(s2[i]):
#             return s1
#         elif ord(s1[i]) > ord(s2[i]):
#             return s1[:i]
#     return s1[:min_l]

def compare_and_truncate(s1,s2):
    if s1 > s2:
        i = 0
        while i < len(s2) and s1[i] == s2[i]:
            i += 1
        return s1[:i]
    return s1



for i in range(len(ss)-2,-1,-1):
    ss[i] = compare_and_truncate(ss[i],ss[i+1])

ans = ""
for s in ss:
    ans += s + "\n"

print(ans)


n = int(input())
a = [input() for i in range(n)]
for i in range(n - 1, 0, -1):
	b = a[i]
	c = a[i - 1]
	l1 = len(b)
	l2 = len(c)
	for j in range(min(l1, l2)):
		if b[j] < c[j]:
			a[i - 1] = c[:j]
			break
		elif b[j] > c[j]: break
	else:
		if l2 > l1:
			a[i - 1] = a[i]
print('\n'.join(a))