s,t,n,m,r=map(int,input().split())#a有s列t行 b有n列m行
A=[]
B=[]
for i in range(s):
w=[int(x) for x in input().split()]
if s==1:
A=w
else:
A.append(w)
for i in range(n):
p=[int(x) for x in input().split()]
if n==1:
B=p
else:
B.append(p)
suma=0
num=0
k=0
ans=[]
sumb=0
dis=0
if s==1:
for i in A:
suma+=i
for i in range(m-t+1):
for j in range(i,t+i):
sumb+=B[j]
if B[j]!=A[k]:
dis+=1
k+=1
sdis=dis
if sdis<=r :
ans.append(abs(suma-sumb))
num+=1
#print(sdis,ans)
sumb=0
dis=0
k=0
elif s>1:
for row in A:
for element in row:
suma+=element
for k in range(n-s+1):
for l in range(m-t+1):
for i in range(s):
for j in range(t):
sumb+=B[k+i][l+j]
if B[k+i][l+j]!=A[i][j]:
dis+=1
sdis=dis
if sdis<=r :
ans.append(abs(suma-sumb))
num+=1
sumb=0
dis=0
if ans==[]:
print("0")
print("-1")
else:
print(num)
print(min(ans))