l = [int(i) for i in input().split(" ")]

h = l[0]

w = l[1]



m = []

m_t = []

m_tt = []

# .のみの行を取り除く

for i in range(h):

    row = list(eval(input()))

    if "#" not in row:

        pass

    else:

        m.append(row)



# 転置して.のみの行を取り除く

for i in range(w):

    row = []

    for j in range(len(m)):

        row.append(m[j][i])

    if "#" not in row:

        pass

    else:

        m_t.append(row)



# 再び転置する

for i in range(len(m)):

    row = []

    for j in range(len(m_t)):

        row.append(m_t[j][i])

    m_tt.append(row)



for row in m_tt:

    print(("".join(row)))

l = [int(i) for i in input().split(" ")]

h = l[0]

w = l[1]

m = []



def trans(matrix):

    t_matrix = []

    h = len(matrix)

    w = len(matrix[0])

    for i in range(w):

        row = []

        for j in range(h):

            row.append(matrix[j][i])

        t_matrix.append(row)

    return t_matrix



def remove_dot(matrix):

    new_matrix = []

    for row in matrix:

        if "#" not in row:

            pass

        else:

            new_matrix.append(row)

    return new_matrix



for i in range(h):

    m.append(list(eval(input())))

for i in range(2):

    m = remove_dot(m)

    m = trans(m)

for row in m:

    print(("".join(row)))

l = [int(i) for i in input().split(" ")]
h = l[0]
w = l[1]
m = []
m_t = []
m_tt = []
# .のみの行を取り除く
for i in range(h):
    row = list(eval(input()))
    if "#" not in row:
        pass
    else:
        m.append(row)
# 転置して.のみの行を取り除く
for i in range(w):
    row = []
    for j in range(len(m)):
        row.append(m[j][i])
    if "#" not in row:
        pass
    else:
        m_t.append(row)
# 再び転置する
for i in range(len(m)):
    row = []
    for j in range(len(m_t)):
        row.append(m_t[j][i])
    m_tt.append(row)
for row in m_tt:
    print(("".join(row)))

l = [int(i) for i in input().split(" ")]
h = l[0]
w = l[1]
m = []


def trans(matrix):
    t_matrix = []
    h = len(matrix)
    w = len(matrix[0])
    for i in range(w):
        row = []
        for j in range(h):
            row.append(matrix[j][i])
        t_matrix.append(row)
    return t_matrix


def remove_dot(matrix):
    new_matrix = []
    for row in matrix:
        if "#" not in row:
            pass
        else:
            new_matrix.append(row)
    return new_matrix


for i in range(h):
    m.append(list(eval(input())))
for i in range(2):
    m = remove_dot(m)
    m = trans(m)
for row in m:
    print(("".join(row)))

-m_t = [] -m_tt = [] -# .のみの行を取り除く + + +def trans(matrix): +    t_matrix = [] +    h = len(matrix) +    w = len(matrix[0]) +    for i in range(w): +        row = [] +        for j in range(h): +            row.append(matrix[j][i]) +        t_matrix.append(row) +    return t_matrix + + +def remove_dot(matrix): +    new_matrix = [] +    for row in matrix: +        if "#" not in row: +            pass +        else: +            new_matrix.append(row) +    return new_matrix + + -    row = list(eval(input())) -    if "#" not in row: -        pass -    else: -        m.append(row) -# 転置して.のみの行を取り除く -for i in range(w): -    row = [] -    for j in range(len(m)): -        row.append(m[j][i]) -    if "#" not in row: -        pass -    else: -        m_t.append(row) -# 再び転置する -for i in range(len(m)): -    row = [] -    for j in range(len(m_t)): -        row.append(m_t[j][i]) -    m_tt.append(row) -for row in m_tt: +    m.append(list(eval(input()))) +for i in range(2): +    m = remove_dot(m) +    m = trans(m) +for row in m: