n, m = map(int, input().split())
str = []
for i in range(n):
str.append(input())
z = 'left'
for i in range(n):
if str[i] == '</CENTER>' or str[i] == '</RIGHT>':
z = 'left'
elif str[i] == '<CENTER>':
z = 'center'
elif str[i] == '<RIGHT>':
z = 'right'
else:
arr = list(str[i].split())
arr.append('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
j = 0
if z == 'left':
while j < len(arr)-1:
if len(arr[j]) + len(arr[j + 1]) + 1 > m:
print(arr[j]+'-'*(m-len(arr[j])))
else:
print(arr[j] + '-' + arr[j+1] + '-' * (m - (len(arr[j]) + len(arr[j + 1]) + 1)))
j += 1
j += 1
elif z == 'right':
while j < len(arr)-1:
if len(arr[j]) + len(arr[j + 1]) + 1 > m:
print('-'*(m-len(arr[j]))+arr[j])
else:
print('-' * (m - (len(arr[j]) + len(arr[j + 1]) + 1)) + arr[j] + '-' + arr[j + 1])
j += 1
j += 1
elif z == 'center':
while j < len(arr)-1:
if len(arr[j]) + len(arr[j + 1]) + 1 > m:
if (m - len(arr[j])) % 2 == 1:
print('-' * ((m - len(arr[j])) // 2) + arr[j] + '-' * ((m - len(arr[j])) // 2 + 1))
else:
print('-' * ((m - len(arr[j])) // 2) + arr[j] + '-' * ((m - len(arr[j])) // 2))
else:
q = arr[j] + '-' + arr[j + 1]
print('-' * ((m - len(q)) // 2) + q + '-' * ((m - len(q)) // 2))
j += 1
j += 1