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

a = ['']*h

for i in range(h):

    a[i] = input()

    

row = [False] * h

col = [False] * w



for i in range(h):

    for j in range(w):

        if a[i][j] == '#':

            row[i] = True

            col[j] = True



for i in range(h):

    if row[i]:

        for j in range(w):

            if col[j]:

                print(a[i][j], end = '')

        print()

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

l = []

for i in range(h):

  a = str(eval(input()))

  if a == '.'*w:

    continue

  l.append(a)



skip = []

for i in range(w):

  for j in range(len(l)):

    if l[j][i] == '#':

      break

  else:

    skip.append(i)



skip = set(skip)

l_ = [0]*len(l)

for i in range(len(l)):

  temp = ''

  for j in range(w):

    if j not in skip:

      temp += l[i][j]

  l_[i] = temp

  

for i in range(len(l_)):

  print((l_[i]))
h, w = map(int, input().split())
a = [""] * h
for i in range(h):
    a[i] = input()
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end="")
        print()

h, w = list(map(int, input().split()))
l = []
for i in range(h):
    a = str(eval(input()))
    if a == "." * w:
        continue
    l.append(a)
skip = []
for i in range(w):
    for j in range(len(l)):
        if l[j][i] == "#":
            break
    else:
        skip.append(i)
skip = set(skip)
l_ = [0] * len(l)
for i in range(len(l)):
    temp = ""
    for j in range(w):
        if j not in skip:
            temp += l[i][j]
    l_[i] = temp
for i in range(len(l_)):
    print((l_[i]))

-h, w = map(int, input().split()) -a = [""] * h +h, w = list(map(int, input().split())) +l = [] -    a[i] = input() -row = [False] * h -col = [False] * w -for i in range(h): +    a = str(eval(input())) +    if a == "." * w: +        continue +    l.append(a) +skip = [] +for i in range(w): +    for j in range(len(l)): +        if l[j][i] == "#": +            break +    else: +        skip.append(i) +skip = set(skip) +l_ = [0] * len(l) +for i in range(len(l)): +    temp = "" -        if a[i][j] == "#": -            row[i] = True -            col[j] = True -for i in range(h): -    if row[i]: -        for j in range(w): -            if col[j]: -                print(a[i][j], end="") -        print() +        if j not in skip: +            temp += l[i][j] +    l_[i] = temp +for i in range(len(l_)): +    print((l_[i]))