You are given two arrays $a$ and $b$ of $n$ positive integers each. You can apply the following operation to them any number of times:

Select an index $i$ ($1\leq i\leq n$) and swap $a_i$ with $b_i$ (i. e. $a_i$ becomes $b_i$ and vice versa).

Find the minimum possible value of $\max(a_1, a_2, \ldots, a_n) \cdot \max(b_1, b_2, \ldots, b_n)$ you can get after applying such operation any number of times (possibly zero).


-----Input-----

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 100$) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer $n$ ($1\le n\le 100$) — the length of the arrays.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10000$) where $a_i$ is the $i$-th element of the array $a$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 10000$) where $b_i$ is the $i$-th element of the array $b$.


-----Output-----

For each test case, print a single integer, the minimum possible value of $\max(a_1, a_2, \ldots, a_n) \cdot \max(b_1, b_2, \ldots, b_n)$ you can get after applying such operation any number of times.


-----Examples-----

Input
3
6
1 2 6 5 1 2
3 4 3 2 2 5
3
3 3 3
3 3 3
2
1 2
2 1
Output
18
9
2


-----Note-----

In the first test, you can apply the operations at indices $2$ and $6$, then $a = [1, 4, 6, 5, 1, 5]$ and $b = [3, 2, 3, 2, 2, 2]$, $\max(1, 4, 6, 5, 1, 5) \cdot \max(3, 2, 3, 2, 2, 2) = 6 \cdot 3 = 18$.

In the second test, no matter how you apply the operations, $a = [3, 3, 3]$ and $b = [3, 3, 3]$ will always hold, so the answer is $\max(3, 3, 3) \cdot \max(3, 3, 3) = 3 \cdot 3 = 9$.

In the third test, you can apply the operation at index $1$, then $a = [2, 2]$, $b = [1, 1]$, so the answer is $\max(2, 2) \cdot \max(1, 1) = 2 \cdot 1 = 2$.

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
results = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] < b[i]:
			(a[i], b[i]) = (b[i], a[i])
	results.append(max(a) * max(b))
print('\n'.join(map(str, results)))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	a = 0
	b = 0
	for i in range(n):
		if l[i] > l1[i]:
			(l[i], l1[i]) = (l1[i], l[i])
	print(max(l) * max(l1))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] < b[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))


t = int(input())
answers = []
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	answers.append(max(a) * max(b))
for i in answers:
	print(i)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def solve():
	n = inp()
	for i in range(n):
		k = inp()
		a = inlt()
		b = inlt()
		for j in range(k):
			if a[j] > b[j]:
				temp = a[j]
				a[j] = b[j]
				b[j] = temp
		print(max(a) * max(b))
solve()


def solve(A, B, n):
	for i in range(n):
		if A[i] > B[i]:
			(A[i], B[i]) = (B[i], A[i])
	return max(A) * max(B)
for case in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B, n)
	print(ans)


for i in range(int(input())):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a.index(max(a)) == b.index(max(b)):
		print(max(a) * max(b))
	else:
		for i in range(len(a)):
			if a[i] < b[i]:
				(a[i], b[i]) = (b[i], a[i])
		print(max(a) * max(b))


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(a, b):
	max_a = max(a)
	max_b = max(b)
	if max_a > max_b:
		for i in range(len(a)):
			if a[i] < b[i]:
				tmp = a[i]
				a[i] = b[i]
				b[i] = tmp
	else:
		for i in range(len(a)):
			if a[i] > b[i]:
				tmp = a[i]
				a[i] = b[i]
				b[i] = tmp
	ans = max(a) * max(b)
	return ans

def main():
	num = int(input())
	for _ in range(num):
		_size = int(input())
		a = inlt()
		b = inlt()
		res = solve(a, b)
		print(res)
	return
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = []
	b1 = []
	if max(a) >= max(b):
		for j in range(len(b)):
			if b[j] >= a[j]:
				(a[j], b[j]) = (b[j], a[j])
		print(max(a) * max(b))
	else:
		for j in range(len(a)):
			if a[j] >= b[j]:
				(b[j], a[j]) = (a[j], b[j])
		print(max(a) * max(b))


a = int(input())
for i in range(a):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	for i in range(len(lst1)):
		if lst1[i] > lst2[i]:
			temp = lst1[i]
			lst1[i] = lst2[i]
			lst2[i] = temp
	print(max(lst1) * max(lst2))


for _ in range(int(input())):
	n = int(input())
	a1 = [int(x) for x in input().split()]
	a2 = [int(x) for x in input().split()]
	for i in range(0, n):
		if a2[i] > a1[i]:
			(a2[i], a1[i]) = (a1[i], a2[i])
	x = max(a1)
	y = max(a2)
	print(x * y)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if max(b) > max(a):
		(a, b) = (b.copy(), a.copy())
	maxi = max(a)
	for i in range(n):
		if b[i] > a[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	li = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	x = max(li)
	y = max(li2)
	if x > y:
		l = li
		l2 = li2
	else:
		l = li2
		l2 = li
	a = max(l)
	for i in range(n):
		if l2[i] > l[i]:
			l2[i] = l[i]
	b = max(l2)
	print(a * b)


for i in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] < b[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a_maxx = max(a)
	b_maxx = max(b)
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	a_maxx = max(a)
	b_maxx = max(b)
	ans = a_maxx * b_maxx
	print(ans)


q = int(input())
m = []
for i in range(0, q):
	count = 0
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	for (item1, item2) in zip(a, b):
		temp = item1
		temp2 = item2
		if item1 / item2 < 1:
			a[count] = temp2
			b[count] = temp
		count += 1
	x = max(a)
	y = max(b)
	k = x * y
	print(k)


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = []
	max1 = []
	for i in range(len(arr1)):
		if arr1[i] > arr2[i]:
			max1.append(arr1[i])
			min1.append(arr2[i])
		else:
			max1.append(arr2[i])
			min1.append(arr1[i])
	print(max(max1) * max(min1))


for z in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	for i in range(n):
		if arr1[i] > arr2[i]:
			(arr1[i], arr2[i]) = (arr2[i], arr1[i])
	print(max(arr1) * max(arr2))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
while t > 0:
	n = inp()
	a = inlt()
	b = inlt()
	for i in range(n):
		if a[i] > b[i]:
			(b[i], a[i]) = (a[i], b[i])
	print(max(a) * max(b))
	t -= 1


n = int(input())
for i in range(n):
	k = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	temp = 0
	for j in range(len(a)):
		if a[j] < b[j]:
			temp = a[j]
			a[j] = b[j]
			b[j] = temp
	max_ = max(a) * max(b)
	print(max_)


from sys import stdin

def main():
	t = int(stdin.readline())
	for _ in range(t):
		m = int(stdin.readline())
		a = list(map(int, stdin.readline().split()))
		b = list(map(int, stdin.readline().split()))
		for i in range(m):
			if a[i] > b[i]:
				(a[i], b[i]) = (b[i], a[i])
		print(max(a) * max(b))
main()


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] < brr[i]:
			(arr[i], brr[i]) = (brr[i], arr[i])
	print(max(arr) * max(brr))


def solve(a, b):
	for i in range(len(a)):
		if b[i] > a[i]:
			(b[i], a[i]) = (a[i], b[i])
	return max(a) * max(b)
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = solve(a, b)
	print(r)
	t -= 1


def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	for i in range(n):
		if a[i] < b[i]:
			(aa, bb) = (a[i], b[i])
			(a[i], b[i]) = (bb, aa)
	print(max(a) * max(b))
for i in range(int(input())):
	solve()


t = int(input())
for tt in range(0, t):
	ans = 1
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	for i in range(0, n):
		if arr1[i] > arr2[i]:
			(arr1[i], arr2[i]) = (arr2[i], arr1[i])
	ans = max(arr1) * max(arr2)
	print(ans)


cases = int(input())
answers = []
for _ in range(cases):
	len_of_arr = int(input())
	(l1, l2) = ([int(n1) for n1 in input().split(' ')], [int(n2) for n2 in input().split(' ')])
	max_ = max(l1 + l2)
	if max_ in l1:
		for i in range(len(l2)):
			if l2[i] > l1[i]:
				(l2[i], l1[i]) = (l1[i], l2[i])
	else:
		for i in range(len(l1)):
			if l1[i] > l2[i]:
				(l1[i], l2[i]) = (l2[i], l1[i])
	answers.append(str(max(l1) * max(l2)))
print('\n'.join(answers))


a = int(input())
l = []

def max_(y, y1, x):
	y = list(map(int, y.split(' ')))
	y1 = list(map(int, y1.split(' ')))
	for i in range(x):
		if y1[i] > y[i]:
			t = y1[i]
			y1[i] = y[i]
			y[i] = t
	l.append(y)
	l.append(y1)
for i in range(a):
	x = int(input())
	y = input()
	y1 = input()
	max_(y, y1, x)
for i in range(0, 2 * a, 2):
	print(int(max(l[i])) * int(max(l[i + 1])))


def solution(a, b, p):
	tmpa = a.copy()
	tmpb = b.copy()
	tmpb.sort()
	tmpa.sort()
	maxa = tmpa[-1]
	maxb = tmpb[-1]
	for i in range(p):
		tmp = -1
		if maxa > maxb and a[i] < b[i]:
			tmp = a[i]
			a[i] = b[i]
			b[i] = tmp
		elif maxa <= maxb and a[i] > b[i]:
			tmp = b[i]
			b[i] = a[i]
			a[i] = tmp
	if maxa > maxb:
		b.sort()
		return maxa * b[-1]
	else:
		a.sort()
		return maxb * a[-1]
test_case = int(input())
tc = []
res = []
for test in range(test_case):
	p = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	tc.append({'length': p, 'arra': a, 'arrb': b})
for t in tc:
	res.append(solution(t['arra'], t['arrb'], t['length']))
for x in res:
	print(x)


testnum = int(input())
for i in range(testnum):
	num = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for j in range(num):
		if a[j] < b[j]:
			temp = a[j]
			a[j] = b[j]
			b[j] = temp
	print(max(a) * max(b))


answers = []
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for x in range(n):
		if b[x] > a[x]:
			(b[x], a[x]) = (a[x], b[x])
	ans = max(b) * max(a)
	answers.append(ans)
for i in answers:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))


cas = int(input())
lf = []
for i in range(cas):
	n = int(input())
	l = [int(x) for x in input().split()]
	l1 = [int(x) for x in input().split()]
	a = max(l)
	a1 = max(l1)
	if a > a1:
		s = l.index(a)
		for i in range(n):
			if l1[i] > l1[s]:
				if l1[i] > l[i]:
					temp = l1[i]
					l1[i] = l[i]
					l[i] = temp
	else:
		s = l1.index(a1)
		for i in range(n):
			if l[i] > l[s]:
				if l[i] > l1[i]:
					temp = l[i]
					l[i] = l1[i]
					l1[i] = temp
	lf.append(max(l) * max(l1))
for i in range(len(lf)):
	print(lf[i])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(len(a)):
		if a[i] > b[i]:
			tmp = a[i]
			a[i] = b[i]
			b[i] = tmp
	print(max(a) * max(b))


from collections import Counter
from math import sqrt
import sys
input = sys.stdin.readline
linput = lambda : list(map(int, input().split()))
iinput = lambda : map(int, input().split())

def solve():
	n = int(input())
	a = linput()
	b = linput()
	for i in range(n):
		if a[i] < b[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))
for __ in range(int(input())):
	solve()


def solution():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	b.sort()
	a.sort()
	print(b[-1] * a[-1])
t = int(input())
while t > 0:
	solution()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arrb = list(map(int, input().split()))
	for i in range(n):
		if arr[i] < arrb[i]:
			(arr[i], arrb[i]) = (arrb[i], arr[i])
	print(max(arr) * max(arrb))


from collections import defaultdict
import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if b[i] < a[i]:
			(a[i], b[i]) = (b[i], a[i])
	out = max(a) * max(b)
	print(out)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	c = max(a)
	d = max(b)
	print(c * d)


import math

def Solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	d = []
	for i in range(n):
		c.append(min(a[i], b[i]))
		d.append(max(a[i], b[i]))
	print(max(c) * max(d))
q = int(input())
while q > 0:
	Solve()
	q = q - 1


t = int(input())
while t != 0:
	n = int(input())
	nums1 = [int(x) for x in input().split()]
	nums2 = [int(x) for x in input().split()]
	for i in range(n):
		temp = min(nums1[i], nums2[i])
		nums1[i] = max(nums1[i], nums2[i])
		nums2[i] = temp
	print(max(nums1) * max(nums2))
	t -= 1


T = int(input())
for _ in range(T):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	max1 = 0
	max2 = 0
	for i in range(n):
		if arr1[i] > arr2[i]:
			max1 = max(max1, arr1[i])
			max2 = max(max2, arr2[i])
		else:
			max1 = max(max1, arr2[i])
			max2 = max(max2, arr1[i])
	print(max1 * max2)


for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	for i in range(n):
		if ai[i] > bi[i]:
			p = ai[i]
			ai[i] = bi[i]
			bi[i] = p
	print(max(ai) * max(bi))


n = int(input())
for i in range(n):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for j in range(l):
		if a[j] > b[j]:
			dob = b[j]
			b.insert(j, a[j])
			b.pop(j + 1)
			a.insert(j, dob)
			a.pop(j + 1)
	print(max(a) * max(b))


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	i = int(input())
	arr1 = [int(item) for item in input().split()]
	arr2 = [int(item) for item in input().split()]
	for i in range(len(arr1)):
		if arr1[i] < arr2[i]:
			(arr1[i], arr2[i]) = (arr2[i], arr1[i])
	print(max(arr1) * max(arr2))


from operator import rshift
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
		else:
			continue
	print(max(a) * max(b))


T = int(input())

def main(obj):
	lista = obj.a
	listb = obj.b
	for k in range(obj.length):
		if lista[k] < listb[k]:
			(lista[k], listb[k]) = (listb[k], lista[k])
	return max(lista) * max(listb)

class case:

	def __init__(self, length, a, b):
		self.length = int(length)
		self.a = [int(x) for x in a.split()]
		self.b = [int(j) for j in b.split()]
cases = []
for i in range(T):
	n = input()
	a = input()
	b = input()
	cases.append(case(n, a, b))
for i in range(T):
	print(main(cases[i]))


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = max(l1)
	b = max(l2)
	if a > b:
		for i in range(n):
			if l1[i] < l2[i]:
				(l1[i], l2[i]) = (l2[i], l1[i])
	else:
		for i in range(n):
			if l1[i] > l2[i]:
				(l1[i], l2[i]) = (l2[i], l1[i])
	print(max(l1) * max(l2))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	print(max(a) * max(b))


test = int(input())
for t in range(test):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	for i in range(n):
		if a[i] > b[i]:
			temp = a[i]
			a[i] = b[i]
			b[i] = temp
	print(max(a) * max(b))


t = int(input())
L = []
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	m1 = s1.split()
	m2 = s2.split()
	l1 = []
	l2 = []
	for i in m1:
		l1 += [int(i)]
	for j in m2:
		l2 += [int(j)]
	for i in range(n):
		if l1[i] > l2[i]:
			(l1[i], l2[i]) = (l2[i], l1[i])
	L += [max(l1) * max(l2)]
for i in L:
	print(i)


for t in range(int(input())):
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	(max1, max2) = (-1, -1)
	for i in range(n):
		if A[i] > B[i]:
			max1 = max(A[i], max1)
			max2 = max(B[i], max2)
		else:
			max1 = max(B[i], max1)
			max2 = max(A[i], max2)
	print(max1 * max2)


for _ in range(int(input())):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	mx1 = mx2 = 0
	for z in range(n):
		(x, y) = (lst1[z], lst2[z])
		(x, y) = (min(x, y), max(x, y))
		mx1 = max(mx1, x)
		mx2 = max(mx2, y)
	print(mx1 * mx2)


def main():
	n_testcase = int(input())
	for _ in range(n_testcase):
		n = int(input())
		a = [int(e) for e in input().split()]
		b = [int(e) for e in input().split()]
		solution(n, a, b)

def solution(n, a, b):
	maxA = maxB = 0
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
		maxA = max(a[i], maxA)
		maxB = max(b[i], maxB)
	print(maxA * maxB)
main()


import sys
case = int(sys.stdin.readline())
for _ in range(case):
	num = int(sys.stdin.readline())
	arr_a = list(map(int, sys.stdin.readline().split()))
	arr_b = list(map(int, sys.stdin.readline().split()))
	for i in range(num):
		if arr_a[i] < arr_b[i]:
			temp = arr_a[i]
			arr_a[i] = arr_b[i]
			arr_b[i] = temp
	print(max(arr_a) * max(arr_b))


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		(a[i], b[i]) = (max(a[i], b[i]), min(a[i], b[i]))
	print(max(a) * max(b))
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = a + b
	m1 = max(c)
	if m1 in a:
		for i in range(n):
			if a[i] < b[i]:
				(a[i], b[i]) = (b[i], a[i])
		m2 = max(b)
	else:
		for i in range(n):
			if b[i] < a[i]:
				(a[i], b[i]) = (b[i], a[i])
		m2 = max(a)
	print(m1 * m2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if b[i] > a[i]:
			(a[i], b[i]) = (b[i], a[i])
	ma = max(a)
	mb = max(b)
	re = ma * mb
	print(re)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	mxa = max(a)
	mxb = max(b)
	if mxa > mxb:
		for i in range(n):
			if a[i] < b[i]:
				(b[i], a[i]) = (a[i], b[i])
		print(max(b) * mxa)
	else:
		for i in range(n):
			if b[i] < a[i]:
				(a[i], b[i]) = (b[i], a[i])
		print(max(a) * mxb)


def solve(a, b):
	for i in range(len(a)):
		if a[i] > b[i]:
			aux = a[i]
			a[i] = b[i]
			b[i] = aux
	return max(a) * max(b)
t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split(' ')
	a = list(map(int, a))
	b = input().split(' ')
	b = list(map(int, b))
	print(solve(a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if max(a) > max(b):
		Arra1 = a
		Arra2 = b
	else:
		Arra1 = b
		Arra2 = a
	for i in range(n):
		if Arra1[i] < Arra2[i]:
			(Arra1[i], Arra2[i]) = (Arra2[i], Arra1[i])
	print(max(Arra1) * max(Arra2))


import sys
from math import *
from math import *
from functools import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = max(a)
	mb = max(b)
	if ma > mb:
		for i in range(n):
			if b[i] > a[i]:
				b[i] = a[i]
		print(ma * max(b))
	else:
		for i in range(n):
			if a[i] > b[i]:
				a[i] = b[i]
		print(mb * max(a))


def fun():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (max(a), max(b))
	if x > y:
		for i in range(n):
			if b[i] > a[i]:
				(b[i], a[i]) = (a[i], b[i])
	else:
		for i in range(n):
			if a[i] > b[i]:
				(b[i], a[i]) = (a[i], b[i])
	return max(a) * max(b)

def main():
	for _ in range(int(input())):
		print(fun())
main()


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	n1 = 0
	n2 = 0
	for (ae, be) in zip(a, b):
		if ae > be:
			n1 = max(n1, ae)
			n2 = max(n2, be)
		else:
			n1 = max(n1, be)
			n2 = max(n2, ae)
	print(n1 * n2)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	k1 = max(max(a), max(b))
	k2 = [min(a[k], b[k]) for k in range(n)]
	print(k1 * max(k2))


import sys
inputs = sys.stdin.readlines()
for i in range(1, len(inputs), 3):
	l = int(inputs[i])
	a = list(map(int, inputs[i + 1].split()))
	b = list(map(int, inputs[i + 2].split()))
	for j in range(l):
		if a[j] > b[j]:
			(a[j], b[j]) = (b[j], a[j])
	print(max(a) * max(b))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	for i in range(0, len(bi)):
		if ai[i] < bi[i]:
			(ai[i], bi[i]) = (bi[i], ai[i])
	print(max(ai) * max(bi))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	newA = []
	newB = []
	for i in range(n):
		t = sorted((int(a[i]), int(b[i])))
		newA.append(t[0])
		newB.append(t[1])
	print(max(newA) * max(newB))


def find_min_prod(n, a, b):
	big_max = 0
	small_max = 0
	for (i, j) in zip(a, b):
		smaller = min(i, j)
		larger = max(i, j)
		small_max = max(small_max, smaller)
		big_max = max(big_max, larger)
	return small_max * big_max
T = int(input())
for t in range(T):
	n = int(input())
	a = [int(k) for k in input().split()]
	b = [int(k) for k in input().split()]
	print(find_min_prod(n, a, b))


n = int(input())
for i in range(n):
	g = int(input())
	l = [int(x) for x in input().split()]
	k = [int(x) for x in input().split()]
	for j in range(g):
		if l[j] > k[j]:
			(l[j], k[j]) = (k[j], l[j])
	print(max(l) * max(k))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	max_a = 0
	max_b = 0
	for i in range(n):
		if a[i] < b[i]:
			max_b = max(max_b, a[i])
			max_a = max(max_a, b[i])
		else:
			max_b = max(max_b, b[i])
			max_a = max(max_a, a[i])
	print(max_a * max_b)


for i in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p1 = max(a) * max(b)
	for i in range(0, n):
		if b[i] < a[i]:
			(a[i], b[i]) = (b[i], a[i])
	p2 = max(a) * max(b)
	print(min(p1, p2))


outputs = []
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	for i in range(n):
		if a[i] < b[i]:
			(a[i], b[i]) = (b[i], a[i])
	outputs.append(max(a) * max(b))
print(*outputs, sep='\n')


t = int(input())

def lol(a, b, k, n):
	for i in range(n):
		if a[i] > b[i]:
			(a[i], b[i]) = (b[i], a[i])
	return max(a)
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = max(a)
	l = max(b)
	if k < l:
		m = lol(a, b, k, n)
		print(m * l)
	else:
		m = lol(b, a, l, n)
		print(m * k)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > b[i]:
			temp = a[i]
			a[i] = b[i]
			b[i] = temp
	print(max(a) * max(b))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 100000
	x = max(max(a), max(b))
	for i in range(n):
		a[i] = min(a[i], b[i])
	print(x * max(a))