• + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    
    
    
    first_multiple_input = input().rstrip().split()
    
    n = int(first_multiple_input[0])
    
    m = int(first_multiple_input[1])
    
    matrix = []
    for _ in range(n):
        matrix_item = input()
        matrix.append(matrix_item)
    string=""
    for i in range(m):
        for j in range(n):
            string+=(matrix[j][i])
    i=0
    string1=[]
    stri=""
    while (i<len(string) and not (string[i].isalnum())):
        stri+=string[i]
        i+=1
    print(stri, end="")
    flag=(len(stri)==len(string))
    while (i<len(string)):
        stri=""
        while (i<len(string) and string[i].isalnum()):
            stri+=string[i]
            i+=1
        while (i<len(string) and not (string[i].isalnum())):
            i+=1
        string1.append(stri)
    i=len(string)-1
    stri=""
    while (i>-1 and not (string[i].isalnum())):
        stri+=string[i]
        i-=1
    print(" ".join(string1),end="")
    while(not(flag)):
        print(stri[::-1])
        flag=True