n=int(input())
list=[]
#creating list
for i in range (0, n):
list.append( int(input()) )
min = list.index(min(list))
max = list.index(max(list))
list[ min ], list[ max ] = list[ max ], list[ min ]
print(list)
n=int(input())
list=[]
#creating list
for i in range (0, n):
list.append( int(input()) )
min = list.index(min(list))
max = list.index(max(list))
list[ min ], list[ max ] = list[ max ], list[ min ]
print(list)