h, w = list(map(int,input().split()))

a = [eval(input()) for _ in range(h)]



remove_a = []

for i in range(h):

    if '#' in a[i]:

        remove_a.append(list(a[i]))



n = len(remove_a)

l = []

for i in range(w):

    s = ''

    for j in range(n):

        s += remove_a[j][i]

    if '#' in s:

        l.append(list(s))



ans = ''

for i in range(len(l[0])):

    s = ''

    for j in range(len(l)):

        s += l[j][i]

    ans += s

    if i != len(l[0])-1:

        ans += '\n'

print(ans)
h, w = list(map(int,input().split()))

a = [list(eval(input())) for _ in range(h)]



yoko = []

for i in range(h):

    seta = set(a[i])

    if '#' in seta:

        yoko.append(a[i])



h = len(yoko)

w = len(yoko[0])

for i in range(w):

    tate = []

    for j in range(h):

        tate.append(yoko[j][i])

    settate = set(tate)

    if '#'not in settate:

        for j in range(h):

            yoko[j][i] = ''



ans = ''

for i in range(h):

    c = ''.join(yoko[i])

    ans += c

    if i != h-1:

        ans += '\n'

print(ans)
h, w = list(map(int, input().split()))
a = [eval(input()) for _ in range(h)]
remove_a = []
for i in range(h):
    if "#" in a[i]:
        remove_a.append(list(a[i]))
n = len(remove_a)
l = []
for i in range(w):
    s = ""
    for j in range(n):
        s += remove_a[j][i]
    if "#" in s:
        l.append(list(s))
ans = ""
for i in range(len(l[0])):
    s = ""
    for j in range(len(l)):
        s += l[j][i]
    ans += s
    if i != len(l[0]) - 1:
        ans += "\n"
print(ans)

h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
yoko = []
for i in range(h):
    seta = set(a[i])
    if "#" in seta:
        yoko.append(a[i])
h = len(yoko)
w = len(yoko[0])
for i in range(w):
    tate = []
    for j in range(h):
        tate.append(yoko[j][i])
    settate = set(tate)
    if "#" not in settate:
        for j in range(h):
            yoko[j][i] = ""
ans = ""
for i in range(h):
    c = "".join(yoko[i])
    ans += c
    if i != h - 1:
        ans += "\n"
print(ans)

-a = [eval(input()) for _ in range(h)] -remove_a = [] +a = [list(eval(input())) for _ in range(h)] +yoko = [] -    if "#" in a[i]: -        remove_a.append(list(a[i])) -n = len(remove_a) -l = [] +    seta = set(a[i]) +    if "#" in seta: +        yoko.append(a[i]) +h = len(yoko) +w = len(yoko[0]) -    s = "" -    for j in range(n): -        s += remove_a[j][i] -    if "#" in s: -        l.append(list(s)) +    tate = [] +    for j in range(h): +        tate.append(yoko[j][i]) +    settate = set(tate) +    if "#" not in settate: +        for j in range(h): +            yoko[j][i] = "" -for i in range(len(l[0])): -    s = "" -    for j in range(len(l)): -        s += l[j][i] -    ans += s -    if i != len(l[0]) - 1: +for i in range(h): +    c = "".join(yoko[i]) +    ans += c +    if i != h - 1: