input_list = []
start = 0
end = 0
def cin_arr(min_len):
global start, end, input_list
start = end
end += min_len
while len(input_list) < end:
input_list.extend(list(map(int, input().split())))
return input_list[start:end]
def cin():
return cin_arr(1)[0]
n = cin()
for z in range(n):
a, b, m = cin_arr(3)
list_a = cin_arr(a)
list_b = cin_arr(b)
print(min(max(list_a), max(list_b), m))