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

a=[]

for i in range(h):

    j=list(input())

    if '#' in j:

        a.append(j)

aa=zip(*[i for i in zip(*a) if '#' in i])

for i in aa:

    print(*i,sep='')

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

a=[]

for i in range(h):

    j=list(eval(input()))

    if '#' in j:

        a.append(j)

aa=list(zip(*[i for i in zip(*a) if '#' in i]))

for i in aa:

    print((''.join(i)))

h, w = map(int, input().split())
a = []
for i in range(h):
    j = list(input())
    if "#" in j:
        a.append(j)
aa = zip(*[i for i in zip(*a) if "#" in i])
for i in aa:
    print(*i, sep="")

h, w = list(map(int, input().split()))
a = []
for i in range(h):
    j = list(eval(input()))
    if "#" in j:
        a.append(j)
aa = list(zip(*[i for i in zip(*a) if "#" in i]))
for i in aa:
    print(("".join(i)))

-h, w = map(int, input().split()) +h, w = list(map(int, input().split())) -    j = list(input()) +    j = list(eval(input())) -aa = zip(*[i for i in zip(*a) if "#" in i]) +aa = list(zip(*[i for i in zip(*a) if "#" in i])) -    print(*i, sep="") +    print(("".join(i)))