Buggy python submission (verdict: Runtime Error):
[h,w,k]=list(map(int,input().split()))
cake=[]
for i in range(h):
	cake.append(list(input()))
ans=[[0 for i in range(w)]for j in range(h)]
num=1
ichigo=[]
for i in range(h):
	for j in range(w):
		if cake[i][j]=="#":
			ans[i][j]=num
			ichigo.append([i,j,num])
			num+=1
for i in range(len(ichigo)):
	yoko=ichigo[i][1]+1
	while True:
		if yoko==h:
			break
		elif ans[ichigo[i][0]][yoko]==0:
			ans[ichigo[i][0]][yoko]=ichigo[i][2]
			yoko+=1
		else:
			break
for i in range(len(ichigo)):
	left=ichigo[i][1]-1
	while True:
		if left<0:
			break
		elif ans[ichigo[i][0]][left]==0:
			ans[ichigo[i][0]][left]=ichigo[i][2]
			left-=1
		else:
			break

for i in reversed(range(ichigo[0][0])):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i+1][j]

for i in range(ichigo[0][0],h):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i-1][j]

for i in range(h):
	for j in range(w):
		print(ans[i][j], end=" ")
	print( )
	

Fixed submission:
[h,w,k]=list(map(int,input().split()))
cake=[]
for i in range(h):
	cake.append(list(input()))
ans=[[0 for i in range(w)]for j in range(h)]
num=1
ichigo=[]
for i in range(h):
	for j in range(w):
		if cake[i][j]=="#":
			ans[i][j]=num
			ichigo.append([i,j,num])
			num+=1
for i in range(len(ichigo)):
	yoko=ichigo[i][1]+1
	while True:
		if yoko==w:
			break
		elif ans[ichigo[i][0]][yoko]==0:
			ans[ichigo[i][0]][yoko]=ichigo[i][2]
			yoko+=1
		else:
			break
for i in range(len(ichigo)):
	left=ichigo[i][1]-1
	while True:
		if left<0:
			break
		elif ans[ichigo[i][0]][left]==0:
			ans[ichigo[i][0]][left]=ichigo[i][2]
			left-=1
		else:
			break

for i in reversed(range(ichigo[0][0])):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i+1][j]

for i in range(ichigo[0][0],h):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i-1][j]

for i in range(h):
	for j in range(w):
		print(ans[i][j], end=" ")
	print( )

Buggy python submission (verdict: Runtime Error):
[h,w,k]=list(map(int,input().split()))
cake=[]
for i in range(h):
	cake.append(list(map(int,input().split())))
ans=[[0 for i in range(w)]for j in range(h)]
num=1
ichigo=[]
for i in range(h):
	for j in range(w):
		if cake[i][j]=="#":
			ans[i][j]=num
			ichigo.append([i,j,num])
			num+=1
for i in range(len(ichigo)):
	yoko=ichigo[i][1]+1
	while True:
		if yoko==h:
			break
		elif ans[ichigo[i][0]][yoko]==0:
			ans[ichigo[i][0]][yoko]=ichigo[i][2]
			yoko+=1
		else:
			break
for i in range(len(ichigo)):
	left=ichigo[i][1]-1
	while True:
		if left<0:
			break
		elif ans[ichigo[i][0]][left]==0:
			ans[ichigo[i][0]][left]=ichigo[i][2]
			left-=1
		else:
			break

for i in reversed(range(ichigo[0][0])):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i+1][j]

for i in range(ichigo[0][0],h):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i-1][j]

for i in range(h):
	for j in range(w):
		print(ans[i][j], end=" ")
	print( )
	

Fixed submission:
[h,w,k]=list(map(int,input().split()))
cake=[]
for i in range(h):
	cake.append(list(input()))
ans=[[0 for i in range(w)]for j in range(h)]
num=1
ichigo=[]
for i in range(h):
	for j in range(w):
		if cake[i][j]=="#":
			ans[i][j]=num
			ichigo.append([i,j,num])
			num+=1
for i in range(len(ichigo)):
	yoko=ichigo[i][1]+1
	while True:
		if yoko==w:
			break
		elif ans[ichigo[i][0]][yoko]==0:
			ans[ichigo[i][0]][yoko]=ichigo[i][2]
			yoko+=1
		else:
			break
for i in range(len(ichigo)):
	left=ichigo[i][1]-1
	while True:
		if left<0:
			break
		elif ans[ichigo[i][0]][left]==0:
			ans[ichigo[i][0]][left]=ichigo[i][2]
			left-=1
		else:
			break

for i in reversed(range(ichigo[0][0])):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i+1][j]

for i in range(ichigo[0][0],h):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i-1][j]

for i in range(h):
	for j in range(w):
		print(ans[i][j], end=" ")
	print( )