n = int(input())
m = int(input())
matrix = [[int(input()) for i in range(n)] for z in range(m)]
maximum = matrix[0][0]
id = 0
for i in range(n):
if max(matrix[i]) > maximum:
maximum = max(matrix[i])
id = i
matrix += [matrix[id]]
print(matrix)
n = int(input())
m = int(input())
matrix = [[int(input()) for i in range(n)] for z in range(m)]
maximum = matrix[0][0]
id = 0
for i in range(n):
if max(matrix[i]) > maximum:
maximum = max(matrix[i])
id = i
matrix += [matrix[id]]
print(matrix)