Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.

Recently Xenia has bought $n_r$ red gems, $n_g$ green gems and $n_b$ blue gems. Each of the gems has a weight.

Now, she is going to pick three gems.

Xenia loves colorful things, so she will pick exactly one gem of each color.

Xenia loves balance, so she will try to pick gems with little difference in weight.

Specifically, supposing the weights of the picked gems are $x$, $y$ and $z$, Xenia wants to find the minimum value of $(x-y)^2+(y-z)^2+(z-x)^2$. As her dear friend, can you help her?


-----Input-----

The first line contains a single integer $t$ ($1\le t \le 100$)  — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains three integers $n_r,n_g,n_b$ ($1\le n_r,n_g,n_b\le 10^5$)  — the number of red gems, green gems and blue gems respectively.

The second line of each test case contains $n_r$ integers $r_1,r_2,\ldots,r_{n_r}$ ($1\le r_i \le 10^9$)  — $r_i$ is the weight of the $i$-th red gem.

The third line of each test case contains $n_g$ integers $g_1,g_2,\ldots,g_{n_g}$ ($1\le g_i \le 10^9$)  — $g_i$ is the weight of the $i$-th green gem.

The fourth line of each test case contains $n_b$ integers $b_1,b_2,\ldots,b_{n_b}$ ($1\le b_i \le 10^9$)  — $b_i$ is the weight of the $i$-th blue gem.

It is guaranteed that $\sum n_r \le 10^5$, $\sum n_g \le 10^5$, $\sum n_b \le 10^5$ (the sum for all test cases).


-----Output-----

For each test case, print a line contains one integer  — the minimum value which Xenia wants to find.


-----Examples-----

Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14


-----Note-----

In the first test case, Xenia has the following gems:

If she picks the red gem with weight $7$, the green gem with weight $6$, and the blue gem with weight $4$, she will achieve the most balanced selection with $(x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14$.

Difficulty: MEDIUM_HARD

Solutions:
import bisect
from itertools import permutations
for _ in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	r = sorted(list(map(int, input().split())))
	g = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	all = [r, g, b]
	ans = float('inf')
	for a in permutations(all):
		for i in a[0]:
			(j, k) = (bisect.bisect(a[1], i) - 1, min(len(a[2]) - 1, bisect.bisect_left(a[2], i)))
			ans = min(ans, (i - a[1][j]) ** 2 + (i - a[2][k]) ** 2 + (a[1][j] - a[2][k]) ** 2)
	print(ans)


q = int(input())

def solve(a, b, c, na, nc):
	ans = -1
	for d in b:
		if a[0] > d or c[-1] < d:
			continue
		l = -1
		r = na
		m = (na - 1) // 2
		while l < r - 1:
			m = (l + r) // 2
			if a[m] <= d and m == na - 1:
				break
			if a[m] <= d and a[m + 1] <= d:
				if l == r - 2:
					m += 1
					break
				l = m
			elif a[m] > d:
				if l == r - 2:
					m -= 1
					break
				r = m
			else:
				break
		aa = a[m]
		l = -1
		r = nc
		m = (nc - 1) // 2
		while l < r - 1:
			m = (l + r) // 2
			if c[m] >= d and m == 0:
				break
			if c[m] >= d and c[m - 1] >= d:
				if l == r - 2:
					m -= 1
					break
				r = m
			elif c[m] < d:
				if l == r - 2:
					m += 1
					break
				l = m
			else:
				break
		cc = c[m]
		nans = (aa - d) ** 2 + (d - cc) ** 2 + (aa - cc) ** 2
		ans = nans if ans == -1 or nans < ans else ans
	return ans if ans >= 0 else (a[0] - b[0]) ** 2 + (b[0] - c[0]) ** 2 + (c[0] - a[0]) ** 2
for _ in range(q):
	(nr, ng, nb) = map(int, input().split())
	r = [int(i) for i in input().split()]
	g = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	r.sort()
	g.sort()
	b.sort()
	ans = solve(r, g, b, nr, nb)
	ans = min(ans, solve(b, g, r, nb, nr))
	ans = min(ans, solve(g, r, b, ng, nb))
	ans = min(ans, solve(b, r, g, nb, ng))
	ans = min(ans, solve(r, b, g, nr, ng))
	ans = min(ans, solve(g, b, r, ng, nr))
	print(ans)


from sys import stdin
input = stdin.readline
q = int(input())

def cyk(l1, l2, l3, len1, len2, len3):
	wynik = 65872346587623475642374982383247
	i1 = 0
	i3 = 0
	for i2 in range(len2):
		while True:
			dupa = 0
			if i1 < len1 - 1 and l1[i1 + 1] <= l2[i2]:
				i1 += 1
				dupa += 1
			if i3 > 0 and l3[i3 - 1] >= l2[i2]:
				i3 -= 1
				dupa += 1
			if i3 < len3 - 1 and l3[i3] < l2[i2]:
				i3 += 1
				dupa += 1
			if dupa == 0:
				break
		if l1[i1] <= l2[i2] and l2[i2] <= l3[i3]:
			wynik = min(wynik, (l1[i1] - l2[i2]) ** 2 + (l2[i2] - l3[i3]) ** 2 + (l1[i1] - l3[i3]) ** 2)
	return wynik
for _ in range(q):
	(r, g, b) = map(int, input().split())
	lr = list(map(int, input().split()))
	lg = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	lr.sort()
	lg.sort()
	lb.sort()
	lr.append(2349349237489237498233)
	lg.append(32964892374982374892384234234234234329)
	lb.append(23964892364892346264873242423423423423423423423423423787878878)
	ler = len(lr)
	leg = len(lg)
	leb = len(lb)
	c1 = cyk(lr, lg, lb, ler, leg, leb)
	c2 = cyk(lg, lr, lb, leg, ler, leb)
	c3 = cyk(lr, lb, lg, ler, leb, leg)
	c4 = cyk(lg, lb, lr, leg, leb, ler)
	c5 = cyk(lb, lr, lg, leb, ler, leg)
	c6 = cyk(lb, lg, lr, leb, leg, ler)
	print(min(c1, c2, c3, c4, c5, c6))


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from bisect import bisect_right, bisect_left
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def fun(red, blue, green):
	ans = 9 * 10 ** 18
	for i in range(len(blue)):
		pos1 = bisect_right(red, blue[i])
		pos2 = bisect_left(green, blue[i])
		if pos1 == 0 or pos2 == len(green):
			continue
		(x, y, z) = (red[pos1 - 1], blue[i], green[pos2])
		val = (x - y) ** 2 + (x - z) ** 2 + (y - z) ** 2
		ans = min(ans, val)
	return ans

def main():
	for _ in range(int(input())):
		(r, b, g) = inpt()
		red = inpt()
		blue = inpt()
		green = inpt()
		red.sort()
		blue.sort()
		green.sort()
		ans = min(fun(red, blue, green), fun(red, green, blue), fun(blue, red, green), fun(blue, green, red), fun(green, red, blue), fun(green, blue, red))
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def cal(x, y, z):
	return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x)

def lb(val, arr):
	if val >= arr[len(arr) - 1]:
		return arr[len(arr) - 1]
	if val <= arr[0]:
		return arr[0]
	l = 0
	r = len(arr)
	while r - l > 1:
		mid = (r + l) // 2
		if arr[mid] == val:
			return arr[mid]
		if arr[mid] < val:
			l = mid
		if arr[mid] > val:
			r = mid
	l2 = l + 1
	if abs(arr[l2] - val) < abs(arr[l] - val):
		return arr[l2]
	return arr[l]

def solve():
	t = int(input())
	while t > 0:
		mn = 3 * 10 ** 18
		(nr, ng, nb) = map(int, input().split())
		rs = sorted(list(map(int, input().split())))
		gs = sorted(list(map(int, input().split())))
		bs = sorted(list(map(int, input().split())))
		for r in rs:
			g = lb(r, gs)
			b = lb(r, bs)
			mn = min(mn, cal(r, g, b))
		for g in gs:
			r = lb(g, rs)
			b = lb(g, bs)
			mn = min(mn, cal(r, g, b))
		for b in bs:
			r = lb(b, rs)
			g = lb(b, gs)
			mn = min(mn, cal(r, g, b))
		print(mn)
		t -= 1
solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bis

def dist(p1, p2, p3):
	a1 = p1 - p2
	a2 = p1 - p3
	a3 = p2 - p3
	return a1 * a1 + a2 * a2 + a3 * a3

def mindist(red, green, blue):
	r = len(red)
	g = len(green)
	b = len(blue)
	minsofar = dist(red[0], green[0], blue[0])
	for s in range(r):
		p1 = red[s]
		o1 = min(bis(green, p1), g - 1)
		o2 = min(bis(blue, p1), b - 1)
		c2ind1 = o1
		c2ind2 = o2
		if c2ind2 > 0 and blue[c2ind2] > p1:
			c2ind2 -= 1
		c2p2 = green[c2ind1]
		c2p3 = blue[c2ind2]
		d2 = dist(p1, c2p2, c2p3)
		minsofar = min(minsofar, d2)
		c3ind1 = o1
		c3ind2 = o2
		if c3ind1 > 0 and green[c3ind1] > p1:
			c3ind1 -= 1
		c3p2 = green[c3ind1]
		c3p3 = blue[c3ind2]
		d3 = dist(p1, c3p2, c3p3)
		minsofar = min(minsofar, d3)
	return minsofar
for j in range(int(input())):
	(r, g, b) = map(int, input().split())
	red = sorted(map(int, input().split()))
	green = sorted(map(int, input().split()))
	blue = sorted(map(int, input().split()))
	minr = mindist(red, green, blue)
	ming = mindist(green, red, blue)
	minb = mindist(blue, red, green)
	print(min(minr, ming, minb))


import bisect

def final_solve(R, G, B):
	ans1 = []
	for i in range(len(R)):
		j = bisect.bisect(G, R[i])
		if j < len(G) and abs(R[i] - G[j]) < abs(R[i] - G[j - 1]):
			y = G[j]
		else:
			y = G[j - 1]
		m = bisect.bisect(B, R[i])
		if m < len(B) and abs(R[i] - B[m]) < abs(R[i] - B[m - 1]):
			z = B[m]
		else:
			z = B[m - 1]
		ans1.append(solve(R[i], y, z))
	return min(ans1)

def solve(x, y, z):
	return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2
t = int(input())
ans = []
for s in range(t):
	(nr, ng, nb) = [int(x) for x in input().split()]
	r = [int(x) for x in input().split()]
	g = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	r.sort()
	g.sort()
	b.sort()
	ans.append(min(final_solve(r, g, b), final_solve(r, b, g), final_solve(g, b, r), final_solve(g, r, b), final_solve(b, r, g), final_solve(b, g, r)))
for it in ans:
	print(it)


import sys
input = sys.stdin.buffer.readline
from bisect import bisect_left

def prog():
	for _ in range(int(input())):
		(r, g, b) = map(int, input().split())
		red = list(map(int, input().split()))
		green = list(map(int, input().split()))
		blue = list(map(int, input().split()))
		red.sort()
		green.sort()
		blue.sort()
		best = []
		jewels = [red, green, blue]
		nums = [r, g, b]
		for (n1, n2, n3) in [[0, 1, 2], [0, 2, 1], [1, 2, 0]]:
			for i in range(nums[n1]):
				x = jewels[n1][i]
				idxy = bisect_left(jewels[n2], x)
				y_test = []
				if idxy == 0:
					y_test.append(jewels[n2][idxy])
				elif idxy == nums[n2]:
					y_test.append(jewels[n2][idxy - 1])
				elif jewels[n2][idxy] == x:
					y_test.append(x)
				else:
					y_test.append(jewels[n2][idxy - 1])
					y_test.append(jewels[n2][idxy])
				for y in y_test:
					m = (x + y) / 2
					idxz = bisect_left(jewels[n3], m)
					z_test = []
					if idxz == 0:
						z_test.append(jewels[n3][idxz])
					elif idxz == nums[n3]:
						z_test.append(jewels[n3][idxz - 1])
					elif jewels[n3][idxz] == m:
						z_test.append(int(m))
					else:
						z_test.append(jewels[n3][idxz - 1])
						z_test.append(jewels[n3][idxz])
					for z in z_test:
						best.append((x - y) ** 2 + (x - z) ** 2 + (z - y) ** 2)
		print(min(best))
prog()


import sys
input = sys.stdin.readline

def operator(v1, v2, v3):
	return (v1 - v2) ** 2 + (v2 - v3) ** 2 + (v3 - v1) ** 2

def abs_diff(l, g, idx, leng):
	(diff, val) = (abs(l[idx] - g), l[idx])
	while idx < leng - 1:
		idx += 1
		if abs(l[idx] - g) < diff:
			diff = abs(l[idx] - g)
			val = l[idx]
		else:
			return [idx - 1, val]
	return [idx, val]

def alternator(li1, li2, li3, len1, len2, len3):
	global mini
	(fstIdx, trdIdx) = (0, 0)
	for i in li2:
		(fstIdx, fstVal) = abs_diff(li1, i, fstIdx, len1)
		(trdIdx, trdVal) = abs_diff(li3, i, trdIdx, len3)
		if mini > operator(i, fstVal, trdVal):
			mini = operator(i, fstVal, trdVal)
for _ in range(int(input())):
	x = input()
	l1 = sorted(list(set(map(int, input().split()))))
	l2 = sorted(list(set(map(int, input().split()))))
	l3 = sorted(list(set(map(int, input().split()))))
	(n1, n2, n3) = (len(l1), len(l2), len(l3))
	mini = operator(l1[0], l2[0], l3[0])
	alternator(l1, l2, l3, n1, n2, n3)
	alternator(l2, l3, l1, n2, n3, n1)
	alternator(l3, l1, l2, n3, n1, n2)
	print(mini)


import sys
from bisect import bisect_right as bi_r, bisect_left as bi_l
from itertools import permutations
t = int(sys.stdin.readline().rstrip())

def cost(r, g, b):
	return (r - g) ** 2 + (g - b) ** 2 + (b - r) ** 2

def main():
	for _ in range(t):
		(a, b, c) = map(int, sys.stdin.readline().split())
		R = sorted(map(int, sys.stdin.readline().split()))
		G = sorted(map(int, sys.stdin.readline().split()))
		B = sorted(map(int, sys.stdin.readline().split()))
		res = []
		for (X, Y, Z) in permutations([R, G, B]):
			for x in X:
				y = Y[max(bi_r(Y, x) - 1, 0)]
				z = Z[min(bi_l(Z, x), len(Z) - 1)]
				res.append(cost(x, y, z))
		print(min(res))
main()


from bisect import bisect_left, bisect_right

def getf(a, b, c):
	return (a - b) ** 2 + (b - c) ** 2 + (a - c) ** 2

def getcondition(low_arr, mid_arr, high_arr):
	s = 10 ** 20
	for i in mid_arr:
		x_p = bisect_right(high_arr, i)
		x = 10 ** 9
		if x_p != len(high_arr):
			x = min(x, high_arr[x_p])
		if x_p != 0:
			x = min(x, high_arr[x_p - 1])
		y = -10 ** 9
		y_ptr = bisect_left(low_arr, i)
		if y_ptr != 0:
			y = max(y, low_arr[y_ptr - 1])
		if y_ptr != len(low_arr):
			y = max(y, low_arr[y_ptr])
		curr = getf(i, x, y)
		if curr < s:
			s = curr
	return s
for _ in range(int(input())):
	(r, g, b) = map(int, input().split())
	red = sorted(list(map(int, input().split())))
	green = sorted(list(map(int, input().split())))
	blue = sorted(list(map(int, input().split())))
	ans = []
	ans.append(getcondition(red, blue, green))
	ans.append(getcondition(green, blue, red))
	ans.append(getcondition(red, green, blue))
	ans.append(getcondition(blue, green, red))
	ans.append(getcondition(blue, red, green))
	ans.append(getcondition(green, red, blue))
	print(min(ans))


import sys

def lower(num, arr):
	ans = 0
	(low, high) = (0, len(arr) - 1)
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] <= num:
			ans = mid
			low = mid + 1
		else:
			high = mid - 1
	return ans

def upper(num, arr):
	ans = len(arr) - 1
	(low, high) = (0, len(arr) - 1)
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] >= num:
			ans = mid
			high = mid - 1
		else:
			low = mid + 1
	return ans

def solve(red, green, blue):
	g = len(green)
	ans = float('inf')
	for i in range(g):
		a = blue[upper(green[i], blue)]
		b = red[lower(green[i], red)]
		c = green[i]
		q = (a - b) ** 2 + (a - c) ** 2 + (b - c) ** 2
		ans = min(ans, q)
	return ans
t = int(sys.stdin.readline())
for _ in range(t):
	(r, g, bl) = map(int, sys.stdin.readline().split())
	red = list(map(int, sys.stdin.readline().split()))
	green = list(map(int, sys.stdin.readline().split()))
	blue = list(map(int, sys.stdin.readline().split()))
	red.sort()
	green.sort()
	blue.sort()
	(i, j) = (0, 0)
	ans = float('inf')
	a = solve(red, green, blue)
	ans = min(ans, a)
	a = solve(red, blue, green)
	ans = min(ans, a)
	a = solve(blue, red, green)
	ans = min(ans, a)
	a = solve(blue, green, red)
	ans = min(ans, a)
	a = solve(green, red, blue)
	ans = min(ans, a)
	a = solve(green, blue, red)
	ans = min(ans, a)
	print(ans)


from bisect import bisect_left

def fun(arr, val):
	pos = bisect_left(arr, val)
	if pos == 0:
		return arr[0]
	elif pos == len(arr):
		return arr[-1]
	else:
		left = arr[pos - 1]
		if val - left < arr[pos] - val:
			return left
		else:
			return arr[pos]
for t in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	wr = sorted(list(map(int, input().split())))
	wg = sorted(list(map(int, input().split())))
	wb = sorted(list(map(int, input().split())))
	m = 10 ** 20
	for x in wr:
		y = fun(wg, x)
		z = fun(wb, x)
		m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	for y in wg:
		x = fun(wr, y)
		z = fun(wb, y)
		m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	for z in wb:
		y = fun(wg, z)
		x = fun(wr, z)
		m = min(m, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	print(m)


inf = 1 << 128
from bisect import bisect_left, bisect_right
from itertools import permutations

def slv():
	A = []
	(nr, ng, nb) = map(int, input().split())
	RG = [-inf] + list(map(int, input().split())) + [inf]
	GG = [-inf] + list(map(int, input().split())) + [inf]
	BG = [-inf] + list(map(int, input().split())) + [inf]
	RG.sort()
	GG.sort()
	BG.sort()
	A.append(RG)
	A.append(GG)
	A.append(BG)
	ans = inf
	for (i0, i1, i2) in permutations([i for i in range(3)]):
		n = len(A[i1])
		for j in range(1, n - 1):
			vm = A[i1][j]
			vl = A[i0][bisect_right(A[i0], vm) - 1]
			vr = A[i2][bisect_left(A[i2], vm)]
			ans = min(ans, (vm - vl) ** 2 + (vr - vl) ** 2 + (vm - vr) ** 2)
	print(ans)
	return
t = int(input())
for i in range(t):
	slv()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	from bisect import bisect_left
	input = sys.stdin.buffer.readline

	def calc(r, g, b):
		return (r - g) ** 2 + (g - b) ** 2 + (b - r) ** 2
	for _ in range(int(input())):
		(NR, NG, NB) = map(int, input().split())
		R = list(map(int, input().split()))
		G = list(map(int, input().split()))
		B = list(map(int, input().split()))
		R.sort()
		B.sort()
		G.sort()
		ans = float('inf')
		L = R[:]
		M = G[:]
		S = B[:]
		for m in M:
			il = bisect_left(L, m)
			if il == len(L):
				continue
			l = L[il]
			is_ = bisect_left(S, m + 1)
			if is_ == 0:
				continue
			s = S[is_ - 1]
			ans = min(ans, calc(l, m, s))
		L = R[:]
		M = B[:]
		S = G[:]
		for m in M:
			il = bisect_left(L, m)
			if il == len(L):
				continue
			l = L[il]
			is_ = bisect_left(S, m + 1)
			if is_ == 0:
				continue
			s = S[is_ - 1]
			ans = min(ans, calc(l, m, s))
		L = G[:]
		M = R[:]
		S = B[:]
		for m in M:
			il = bisect_left(L, m)
			if il == len(L):
				continue
			l = L[il]
			is_ = bisect_left(S, m + 1)
			if is_ == 0:
				continue
			s = S[is_ - 1]
			ans = min(ans, calc(l, m, s))
		L = G[:]
		M = B[:]
		S = R[:]
		for m in M:
			il = bisect_left(L, m)
			if il == len(L):
				continue
			l = L[il]
			is_ = bisect_left(S, m + 1)
			if is_ == 0:
				continue
			s = S[is_ - 1]
			ans = min(ans, calc(l, m, s))
		L = B[:]
		M = R[:]
		S = G[:]
		for m in M:
			il = bisect_left(L, m)
			if il == len(L):
				continue
			l = L[il]
			is_ = bisect_left(S, m + 1)
			if is_ == 0:
				continue
			s = S[is_ - 1]
			ans = min(ans, calc(l, m, s))
		L = B[:]
		M = G[:]
		S = R[:]
		for m in M:
			il = bisect_left(L, m)
			if il == len(L):
				continue
			l = L[il]
			is_ = bisect_left(S, m + 1)
			if is_ == 0:
				continue
			s = S[is_ - 1]
			ans = min(ans, calc(l, m, s))
		print(ans)
main()


t = int(input())
for i in range(t):
	(r, g, b) = map(int, input().split())
	R = list(map(int, input().split()))
	G = list(map(int, input().split()))
	B = list(map(int, input().split()))
	R.sort()
	G.sort()
	B.sort()
	INF = 10 ** 20
	(h1, h2, h3) = (INF, INF, INF)
	ans = 0
	first = 0
	second = 0
	third = 0
	while first < r and second < g and (third < b):
		if first == 0 and second == 0 and (third == 0):
			ans = (R[first] - G[second]) ** 2 + (B[third] - G[second]) ** 2 + (B[third] - R[first]) ** 2
		if third != b - 1:
			h3 = (R[first] - G[second]) ** 2 + (B[third + 1] - G[second]) ** 2 + (B[third + 1] - R[first]) ** 2
		if second != g - 1:
			h2 = (R[first] - G[second + 1]) ** 2 + (B[third] - G[second + 1]) ** 2 + (B[third] - R[first]) ** 2
		if first != r - 1:
			h1 = (R[first + 1] - G[second]) ** 2 + (B[third] - G[second]) ** 2 + (B[third] - R[first + 1]) ** 2
		h = min(h1, h2, h3)
		if h == h1:
			ans = min(ans, h1)
			first += 1
		elif h == h2:
			ans = min(ans, h2)
			second += 1
		elif h == h3:
			ans = min(ans, h3)
			third += 1
		(h1, h2, h3) = (INF, INF, INF)
	print(ans)


def calc(a, bb, cc):
	return (a - bb) ** 2 + (bb - cc) ** 2 + (cc - a) ** 2

def findMin(x, y, z, nx, ny, nz):
	possibilities = []
	for i in range(nx):
		a = x[i]
		b = ny
		j = -1
		while b > 0:
			while j + b < ny and y[j + b] <= a:
				j += b
			b //= 2
		b = nz
		k = -1
		while b > 0:
			while k + b < nz and z[k + b] <= a:
				k += b
			b //= 2
		if 0 <= j:
			if 0 <= k:
				possibilities.append(calc(a, y[j], z[k]))
			if k + 1 < nz:
				possibilities.append(calc(a, y[j], z[k + 1]))
		if j + 1 < ny:
			if 0 <= k:
				possibilities.append(calc(a, y[j + 1], z[k]))
			if k + 1 < nz:
				possibilities.append(calc(a, y[j + 1], z[k + 1]))
	return min(possibilities)
t = int(input())
for _ in range(t):
	(nr, ng, nb) = [int(x) for x in input().split()]
	r = [int(x) for x in input().split()]
	g = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	r.sort()
	g.sort()
	b.sort()
	ans = min(findMin(r, g, b, nr, ng, nb), findMin(g, r, b, ng, nr, nb), findMin(b, r, g, nb, nr, ng))
	print(ans)


import bisect

def near(li, el, le):
	xx = bisect.bisect_left(li, el)
	if xx == le:
		return li[-1]
	elif xx == 0:
		return li[0]
	elif abs(li[xx - 1] - el) >= abs(li[xx] - el):
		return li[xx]
	else:
		return li[xx - 1]

def ansf(x, y, z):
	return (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2
for _ in range(int(input())):
	(r, g, b) = map(int, input().split())
	rr = list(map(int, input().split()))
	rr.sort()
	gg = list(map(int, input().split()))
	gg.sort()
	bb = list(map(int, input().split()))
	bb.sort()
	ans = float('inf')
	for i in range(r):
		x1 = near(bb, rr[i], b)
		x2 = near(gg, rr[i], g)
		ans = min(ans, ansf(rr[i], x1, x2))
	for i in range(g):
		x1 = near(rr, gg[i], r)
		x2 = near(bb, gg[i], b)
		ans = min(ans, ansf(gg[i], x1, x2))
	for i in range(b):
		x1 = near(rr, bb[i], r)
		x2 = near(gg, bb[i], g)
		ans = min(ans, ansf(bb[i], x1, x2))
	print(ans)


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def calc(a, b, c):
	return (a - b) * (a - b) + (b - c) * (b - c) + (c - a) * (c - a)

def calculateAns(r, g, b):
	temp = []
	for i in range(len(g)):
		val1 = bisect_left(r, g[i])
		val2 = bisect_right(b, g[i])
		if val1 >= len(r):
			val1 = len(r) - 1
		val2 = max(0, val2 - 1)
		temp.append(calc(r[val1], g[i], b[val2]))
	return min(temp)
t = int(input())
while t:
	t -= 1
	(nr, ng, nb) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	brr = list(map(int, input().split()))
	brr.sort()
	crr = list(map(int, input().split()))
	crr.sort()
	ans = []
	ans.append(calculateAns(arr, brr, crr))
	ans.append(calculateAns(crr, brr, arr))
	ans.append(calculateAns(brr, arr, crr))
	ans.append(calculateAns(crr, arr, brr))
	ans.append(calculateAns(arr, crr, brr))
	ans.append(calculateAns(brr, crr, arr))
	print(min(ans))


from bisect import bisect

def calculate(v1, v2, v3):
	return (v1 - v2) ** 2 + (v2 - v3) ** 2 + (v3 - v1) ** 2

def final(a, b_list, c):
	final_close = bisect(b_list, (a + c) / 2)
	if final_close == 0:
		return calculate(a, b_list[final_close], c)
	if final_close == len(b_list):
		return calculate(a, b_list[final_close - 1], c)
	else:
		return min(calculate(a, b_list[final_close], c), calculate(a, b_list[final_close - 1], c))

def solve():
	(n_r, n_g, n_b) = [int(x) for x in input().split()]
	r = [int(x) for x in input().split()]
	g = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	r.sort()
	g.sort()
	b.sort()
	best = int(1e+21)
	for ele in r:
		close_g = bisect(g, ele)
		if close_g != 0:
			best = min(best, final(ele, b, g[close_g - 1]))
		if close_g != n_g:
			best = min(best, final(ele, b, g[close_g]))
		close_b = bisect(b, ele)
		if close_b != 0:
			best = min(best, final(ele, g, b[close_b - 1]))
		if close_b != n_b:
			best = min(best, final(ele, g, b[close_b]))
	print(best)
	return
t = int(input())
for i in range(t):
	solve()


def find(arr, flag, num):
	if flag:
		low = 0
		high = len(arr) - 1
		while low < high:
			mid = (low + high) // 2
			if arr[mid] < num:
				low = mid + 1
			else:
				high = mid - 1
		if arr[low] < num:
			if low != len(arr) - 1:
				return arr[low + 1]
			else:
				return 10 ** 20
		else:
			return arr[low]
	else:
		low = 0
		high = len(arr) - 1
		while low < high:
			mid = (low + high) // 2
			if arr[mid] < num:
				low = mid + 1
			else:
				high = mid - 1
		if arr[low] > num:
			if low != 0:
				return arr[low - 1]
			else:
				return 10 ** 20
		else:
			return arr[low]

def solve(a, b, c):
	ans = 10 ** 20
	for i in b:
		x = find(a, 0, i)
		y = find(c, 1, i)
		ans = min(ans, (i - x) ** 2 + (i - y) ** 2 + (x - y) ** 2)
	return ans
for nt in range(int(input())):
	(n1, n2, n3) = map(int, input().split())
	l1 = sorted(list(map(int, input().split())))
	l2 = sorted(list(map(int, input().split())))
	l3 = sorted(list(map(int, input().split())))
	ans = solve(l1, l2, l3)
	ans = min(ans, solve(l1, l3, l2))
	ans = min(ans, solve(l2, l1, l3))
	ans = min(ans, solve(l2, l3, l1))
	ans = min(ans, solve(l3, l1, l2))
	print(min(ans, solve(l3, l2, l1)))


import sys, heapq as h
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def sq_sum(a, b, c):
	return (a - b) ** 2 + (b - c) ** 2 + (c - a) ** 2

def solve():
	(NR, NG, NB) = getInts()
	Cols = []
	for j in range(3):
		Cols.append(getInts())
		Cols[j].sort()
	best = 3 * 10 ** 18 + 1
	for i in range(3):
		for j in range(3):
			for k in range(3):
				if len(set([i, j, k])) == 3:
					for jj in range(len(Cols[j])):
						arr1 = Cols[j][jj]
						if Cols[j][jj] < Cols[i][0] or Cols[j][jj] > Cols[k][-1]:
							continue
						if Cols[i][0] == arr1:
							arr0 = Cols[i][0]
						elif Cols[i][-1] <= arr1:
							arr0 = Cols[i][-1]
						else:
							left = 0
							right = len(Cols[i]) - 1
							while right - left > 1:
								middle = (left + right) // 2
								if Cols[i][middle] == arr1:
									left = middle
									break
								if Cols[i][middle] < arr1:
									left = middle
								else:
									right = middle
							arr0 = Cols[i][left]
						if Cols[k][-1] == arr1:
							arr2 = Cols[k][-1]
						elif Cols[k][0] >= arr0:
							arr2 = Cols[k][0]
						else:
							left = 0
							right = len(Cols[k]) - 1
							while right - left > 1:
								middle = (left + right) // 2
								if Cols[k][middle] == arr1:
									right = middle
									break
								if Cols[k][middle] > arr1:
									right = middle
								else:
									left = middle
							arr2 = Cols[k][right]
						best = min(best, sq_sum(arr0, arr1, arr2))
	return best
for _ in range(getInt()):
	print(solve())


import sys
from array import array

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def solve(a, b, c):
	res = 4 * 10 ** 18
	(n, m, l) = (len(a), len(b), len(c))
	(j, k) = (0, 0)
	for x in a:
		while j + 1 < m and b[j + 1] <= x:
			j += 1
		while k + 1 < l and c[k] < x:
			k += 1
		res = min(res, (x - b[j]) ** 2 + (b[j] - c[k]) ** 2 + (c[k] - x) ** 2)
	return res
for _ in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	r = sorted(map(int, input().split()))
	g = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	print(min(solve(r, g, b), solve(r, b, g), solve(b, r, g), solve(b, g, r), solve(g, r, b), solve(g, b, r)))


import sys
input = sys.stdin.buffer.readline
from bisect import bisect_left
Q = int(input())
Query = []
for _ in range(Q):
	(n1, n2, n3) = map(int, input().split())
	A1 = list(map(int, input().split()))
	A2 = list(set(map(int, input().split())))
	A3 = list(set(map(int, input().split())))
	Query.append((n1, n2, n3, A1, A2, A3))
for (n1, n2, n3, A1, A2, A3) in Query:
	n2 = len(A2)
	n3 = len(A3)
	A2.sort()
	A3.sort()
	ans = 10 ** 60
	for a in A1:
		i2 = bisect_left(A2, a)
		B2 = []
		if i2 < n2:
			B2.append(A2[i2])
		if i2 < n2 - 1:
			B2.append(A2[i2 + 1])
		if i2 > 0:
			B2.append(A2[i2 - 1])
		for b2 in B2:
			i3 = bisect_left(A3, (a + b2 + 1) // 2)
			B3 = []
			if i3 < n3:
				B3.append(A3[i3])
			if i3 < n3 - 1:
				B3.append(A3[i3 + 1])
			if i3 > 0:
				B3.append(A3[i3 - 1])
			for b3 in B3:
				s = (a - b2) ** 2 + (b2 - b3) ** 2 + (b3 - a) ** 2
				if s < ans:
					ans = s
		i3 = bisect_left(A3, a)
		B3 = []
		if i3 < n3:
			B3.append(A3[i3])
		if i3 < n3 - 1:
			B3.append(A3[i3 + 1])
		if i3 > 0:
			B3.append(A3[i3 - 1])
		for b3 in B3:
			i2 = bisect_left(A2, (a + b3 + 1) // 2)
			B2 = []
			if i2 < n2:
				B2.append(A2[i2])
			if i2 < n2 - 1:
				B2.append(A2[i2 + 1])
			if i2 > 0:
				B2.append(A2[i2 - 1])
			for b2 in B2:
				s = (a - b2) ** 2 + (b2 - b3) ** 2 + (b3 - a) ** 2
				if s < ans:
					ans = s
	print(ans)


from bisect import bisect_left

def take_closest(myList, myNumber):
	pos = bisect_left(myList, myNumber)
	if pos == 0:
		return myList[0]
	if pos == len(myList):
		return myList[-1]
	before = myList[pos - 1]
	after = myList[pos]
	if after - myNumber < myNumber - before:
		return after
	else:
		return before
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	f = []
	a.sort()
	c.sort()
	b.sort()
	for x in a:
		y = take_closest(b, x)
		z = take_closest(c, x)
		f.append((x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	for x in b:
		y = take_closest(a, x)
		z = take_closest(c, x)
		f.append((x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	for x in c:
		y = take_closest(b, x)
		z = take_closest(a, x)
		f.append((x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	print(min(f))


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7

def lower(a, r, x):
	l = 0
	r -= 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if a[m] <= x:
			l = m + 1
			ans = a[m]
		else:
			r = m - 1
	return ans

def upper(a, r, x):
	r -= 1
	l = 0
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if a[m] >= x:
			r = m - 1
			ans = a[m]
		else:
			l = m + 1
	return ans

def solve(a, b, c, x, y, z):
	ans = inf
	for i in a:
		j = lower(b, y, i)
		k = upper(c, z, i)
		if j > -1 and k > -1:
			ans = min(ans, (i - j) ** 2 + (i - k) ** 2 + (k - j) ** 2)
	return ans
for _ in range(I()):
	(x, y, z) = R()
	r = sorted(R())
	g = sorted(R())
	b = sorted(R())
	print(min(solve(r, g, b, x, y, z), solve(r, b, g, x, z, y), solve(b, r, g, z, x, y), solve(b, g, r, z, y, x), solve(g, r, b, y, x, z), solve(g, b, r, y, z, x)))


for f in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	r = list(map(int, input().split()))
	g = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r.sort()
	g.sort()
	b.sort()
	mi = 2 * (r[0] ** 2 + g[0] ** 2 + b[0] ** 2)
	fr = 0
	fg = 0
	fb = 0
	prr = r[0]
	prg = g[0]
	prb = b[0]
	for i in range(ng):
		while r[fr] < g[i] and fr < nr - 1:
			prr = r[fr]
			fr += 1
		while b[fb] < g[i] and fb < nb - 1:
			prb = b[fb]
			fb += 1
		cl1 = prr
		if r[fr] - g[i] < g[i] - prr:
			cl1 = r[fr]
		cl2 = prb
		if b[fb] - g[i] < g[i] - prb:
			cl2 = b[fb]
		cur = (g[i] - cl1) ** 2 + (g[i] - cl2) ** 2 + (cl1 - cl2) ** 2
		mi = min(mi, cur)
	fr = 0
	fg = 0
	fb = 0
	prr = r[0]
	prg = g[0]
	prb = b[0]
	for i in range(nb):
		while g[fg] < b[i] and fg < ng - 1:
			prg = g[fg]
			fg += 1
		while r[fr] < b[i] and fr < nr - 1:
			prr = r[fr]
			fr += 1
		cl1 = prr
		if r[fr] - b[i] < b[i] - prr:
			cl1 = r[fr]
		cl2 = prg
		if g[fg] - b[i] < b[i] - prg:
			cl2 = g[fg]
		cur = (b[i] - cl1) ** 2 + (b[i] - cl2) ** 2 + (cl1 - cl2) ** 2
		mi = min(mi, cur)
	fr = 0
	fg = 0
	fb = 0
	prr = r[0]
	prg = g[0]
	prb = b[0]
	for i in range(nr):
		while g[fg] < r[i] and fg < ng - 1:
			prg = g[fg]
			fg += 1
		while b[fb] < r[i] and fb < nb - 1:
			prb = b[fb]
			fb += 1
		cl1 = prg
		if g[fg] - r[i] < r[i] - prg:
			cl1 = g[fg]
		cl2 = prb
		if b[fb] - r[i] < r[i] - prb:
			cl2 = b[fb]
		cur = (r[i] - cl1) ** 2 + (r[i] - cl2) ** 2 + (cl1 - cl2) ** 2
		mi = min(mi, cur)
	print(mi)


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

def f(a, b, c):
	return (a - b) ** 2 + (a - c) ** 2 + (b - c) ** 2

def bs(arr, x, y):
	(l, r) = (-1, len(arr))
	while r - l > 1:
		m = (l + r) // 2
		if 2 * arr[m] <= x + y:
			l = m
		else:
			r = m
	return (None if l == -1 else arr[l], None if r == len(arr) else arr[r])

def findAns(a, b, c):
	ans = float('inf')
	(pa, pb) = (0, 0)
	while True:
		(bestA, bestB) = bs(c, a[pa], b[pb])
		if bestA is not None:
			if min(a[pa], b[pb]) <= bestA <= max(a[pa], b[pb]):
				ans = min(ans, f(a[pa], b[pb], bestA))
		if bestB is not None:
			if min(a[pa], b[pb]) <= bestB <= max(a[pa], b[pb]):
				ans = min(ans, f(a[pa], b[pb], bestB))
		mn = min(a[pa], b[pb])
		if a[pa] == mn and pa != len(a) - 1:
			pa += 1
		elif b[pb] == mn and pb != len(b) - 1:
			pb += 1
		else:
			break
	return ans

def solve(r, g, b):
	r.sort()
	g.sort()
	b.sort()
	ans = min(findAns(r, g, b), findAns(r, b, g), findAns(g, b, r))
	print(ans)

def main():
	t = int(input())
	for x in range(t):
		(nr, ng, nb) = readInts()
		solve(readInts(), readInts(), readInts())
main()


import sys
import collections
import threading
import itertools

def main():
	testn = int(input())
	for _ in range(testn):
		(nr, ng, nb) = map(int, input().split())
		r = sorted(list(map(int, input().split())))
		g = sorted(list(map(int, input().split())))
		b = sorted(list(map(int, input().split())))
		(i, j, k) = (0, 0, 0)
		ans = (r[i] - g[j]) ** 2 + (g[j] - b[k]) ** 2 + (b[k] - r[i]) ** 2
		permut3 = itertools.permutations([r, g, b])
		for (first, second, third) in permut3:
			(i, j, k) = (0, 0, 0)
			for j in range(len(second)):
				while i < len(first) - 1 and first[i + 1] <= second[j]:
					i += 1
				while k < len(third) - 1 and third[k] < second[j]:
					k += 1
				tmp = (first[i] - second[j]) ** 2 + (second[j] - third[k]) ** 2 + (third[k] - first[i]) ** 2
				if tmp < ans:
					ans = tmp
		print(ans)
input = sys.stdin.readline
sys.setrecursionlimit(2097152)
main()


from itertools import permutations
import sys
from copy import copy, deepcopy
input = sys.stdin.readline
inf = 1000000000
mod = 998244353

def calc(na, nb, nc):
	posa = 0
	posc = 0
	for posb in range(NUM[nb]):
		while posa < NUM[na] - 1 and A[na][posa + 1] <= A[nb][posb]:
			posa += 1
		while posc < NUM[nc] - 1 and A[nc][posc] < A[nb][posb]:
			posc += 1
		last = [A[na][posa], A[nb][posb], A[nc][posc]]
		global ans
		ans = min(ans, (last[0] - last[1]) ** 2 + (last[1] - last[2]) ** 2 + (last[0] - last[2]) ** 2)
for CASES in range(int(input())):
	ans = 3 * inf * inf
	NUM = list(map(int, input().split()))
	A = []
	A.append(sorted(map(int, input().split())))
	A.append(sorted(map(int, input().split())))
	A.append(sorted(map(int, input().split())))
	for i in range(0, 3):
		A[i].sort()
	for (na, nb, nc) in permutations([0, 1, 2]):
		calc(na, nb, nc)
	print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def difference(r, g, b):
	ng = len(g)
	nr = len(r)
	nb = len(b)
	diff = 999999999999999999999999999
	for x in r:
		y = bisect.bisect_left(g, x)
		z = min(bisect.bisect_left(b, x), nb - 1)
		if y == -1 or y == ng or g[y] != x:
			y -= 1
			y = max(0, y)
		if z == -1:
			z = 0
		if g[y] <= x <= b[z]:
			diff = min(diff, (x - g[y]) ** 2 + (g[y] - b[z]) ** 2 + (b[z] - x) ** 2)
	return diff

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		(nr, ng, nb) = ria()
		r = sorted(list(set(ria())))
		g = sorted(list(set(ria())))
		b = sorted(list(set(ria())))
		print(min(difference(r, g, b), difference(r, b, g), difference(g, b, r), difference(g, r, b), difference(b, r, g), difference(b, g, r)))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def solve(l1, l2, l3):
	ans = float('inf')
	for i in l1:
		(x, y) = find(l2, l3, i)
		ans = min(ans, (i - x) ** 2 + (i - y) ** 2 + (x - y) ** 2)
	return ans

def find(arr1, arr2, num):
	(low, high) = (0, len(arr1) - 1)
	while low < high:
		mid = (low + high) // 2
		if arr1[mid] < num:
			low = mid + 1
		else:
			high = mid - 1
	if arr1[low] < num:
		if low != len(arr1) - 1:
			x = arr1[low + 1]
		else:
			x = float('inf')
	else:
		x = arr1[low]
	(low, high) = (0, len(arr2) - 1)
	while low < high:
		mid = (low + high) // 2
		if arr2[mid] < num:
			low = mid + 1
		else:
			high = mid - 1
	if arr2[low] > num:
		if low != 0:
			y = arr2[low - 1]
		else:
			y = float('inf')
	else:
		y = arr2[low]
	return (x, y)
for _ in range(int(input())):
	(r, g, b) = map(int, input().split())
	lr = sorted(list(map(int, input().split())))
	lg = sorted(list(map(int, input().split())))
	lb = sorted(list(map(int, input().split())))
	ans = solve(lr, lg, lb)
	ans = min(ans, solve(lr, lb, lg))
	ans = min(ans, solve(lb, lr, lg))
	ans = min(ans, solve(lb, lg, lr))
	ans = min(ans, solve(lg, lr, lb))
	ans = min(ans, solve(lg, lb, lr))
	print(ans)


from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	(nr, ng, nb) = map(int, input().split(' '))
	r = sorted(list(map(int, input().split(' '))))
	g = sorted(list(map(int, input().split(' '))))
	b = sorted(list(map(int, input().split(' '))))
	rgb = [r, g, b]
	o = 10 ** 9 ** 2
	for m in range(3):
		for l in range(3):
			if m != l:
				r = 3 - m - l
				for mi in range(len(rgb[m])):
					x = rgb[m][mi]
					yi = bisect_left(rgb[l], x)
					zi = bisect_right(rgb[r], x)
					if yi == len(rgb[l]) or zi == 0:
						continue
					y = rgb[l][yi]
					z = rgb[r][zi - 1]
					o = min(o, (x - y) ** 2 + (x - z) ** 2 + (y - z) ** 2)
	print(o)


def val(gems):
	(g1, g2, g3) = gems
	v = (g1 - g2) ** 2 + (g2 - g3) ** 2 + (g3 - g1) ** 2
	return v

def binarysearch(lwr, upr, lst, target, dxn):
	if upr == lwr:
		return lst[lwr]
	elif upr - lwr == 1 and dxn == 1:
		if lst[upr] <= target:
			return lst[upr]
		else:
			return lst[lwr]
	elif upr - lwr == 1 and dxn == -1:
		if lst[lwr] >= target:
			return lst[lwr]
		else:
			return lst[upr]
	else:
		middle = (lwr + upr) // 2
		if lst[middle] > target:
			return binarysearch(lwr, middle, lst, target, dxn)
		elif lst[middle] < target:
			return binarysearch(middle, upr, lst, target, dxn)
		else:
			return target
T = int(input())
for test in range(T):
	gemsno = list(map(int, input().split()))
	gemlists = [list(map(int, input().split())) for col in range(3)]
	for n in range(3):
		gemlists[n].sort()
	perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
	dist = 10 ** 20
	for perm in perms:
		refno = perm[0]
		upw = perm[1]
		dwn = perm[2]
		refgems = gemlists[refno]
		upwgems = gemlists[upw]
		dwngems = gemlists[dwn]
		(dwnl, upwl) = (len(dwngems), len(upwgems))
		for refgem in refgems:
			if upwgems[-1] < refgem:
				gu = upwgems[-1]
			else:
				gu = binarysearch(0, upwl - 1, upwgems, refgem, 1)
			if dwngems[0] > refgem:
				gd = dwngems[0]
			else:
				gd = binarysearch(0, dwnl - 1, dwngems, refgem, -1)
			gems = [refgem, gu, gd]
			v = val(gems)
			dist = min(dist, v)
	print(dist)


import itertools as it
import os

def solve(xs, ys, zs):
	prevs = [None] * 3
	streak = []
	streak_type = None
	best = float('inf')
	for (item, t) in sorted(it.chain(map(lambda a: (a, 0), xs), map(lambda a: (a, 1), ys), map(lambda a: (a, 2), zs))):
		prevs[t] = item
		if t == streak_type:
			streak.append(item)
		elif streak_type is None or any((x == None for x in prevs)):
			streak = [item]
			streak_type = t
		else:
			(i1, i2) = [k for k in [0, 1, 2] if k != streak_type]
			v = (prevs[i1] - prevs[i2]) ** 2
			for s in streak:
				m = v + (prevs[i1] - s) ** 2 + (prevs[i2] - s) ** 2
				best = min(best, m)
			streak = [item]
			streak_type = t
	return best
solve([1, 2], [5, 4], [6, 7])

def pp(input):
	T = int(input())
	for i in range(T):
		input()
		s = (map(int, input().split()) for _ in range(3))
		print(solve(*s))
if 'paalto' in os.getcwd():
	from string_source import string_source
	pp(string_source('5\n2 2 3\n7 8\n6 3\n3 1 4\n1 1 1\n1\n1\n1000000000\n2 2 2\n1 2\n5 4\n6 7\n2 2 2\n1 2\n3 4\n6 7\n3 4 1\n3 2 1\n7 3 3 4\n6'))
else:
	pp(input)


def cases(array1, array2, array3):
	n1 = len(array1)
	n2 = len(array2)
	n3 = len(array3)
	currmin = 0
	currmax = 0
	ans = 92523523623423452323623
	for ele in array2:
		while currmin + 1 < n1 and array1[currmin + 1] <= ele:
			currmin += 1
		while currmax + 1 < n3 and array3[currmax] < ele:
			currmax += 1
		if array1[currmin] > ele and ele > array3[currmax]:
			continue
		ans = min(ans, (ele - array1[currmin]) ** 2 + (ele - array3[currmax]) ** 2 + (array1[currmin] - array3[currmax]) ** 2)
	return ans
for _ in range(int(input())):
	(n1, n2, n3) = map(int, input().split())
	array1 = list(map(int, input().split()))
	array2 = list(map(int, input().split()))
	array3 = list(map(int, input().split()))
	array1.sort()
	array2.sort()
	array3.sort()
	t1 = cases(array1, array2, array3)
	t2 = cases(array1, array3, array2)
	t3 = cases(array2, array1, array3)
	t4 = cases(array2, array3, array1)
	t5 = cases(array3, array1, array2)
	t6 = cases(array3, array2, array1)
	print(min(t1, t2, t3, t4, t5, t6))


import sys
import bisect
input = sys.stdin.readline
out = []
t = int(input())
for _ in range(t):
	(nr, ng, nb) = map(int, input().split())
	r = list(map(int, input().split()))
	g = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r.sort()
	g.sort()
	b.sort()
	best = 10 ** 24
	for (x, y, z) in ((r, g, b), (g, r, b), (b, g, r)):
		for i in range(len(x)):
			new = 0
			v = []
			for l in (y, z):
				ind = bisect.bisect(l, x[i])
				add = (l[ind - 1] - x[i]) ** 2
				v.append(l[ind - 1])
				if ind < len(l):
					if (l[ind] - x[i]) ** 2 < add:
						v[-1] = l[ind]
						add = (l[ind] - x[i]) ** 2
				new += add
			new += (v[0] - v[1]) ** 2
			if new < best:
				best = new
	out.append(best)
print('\n'.join(map(str, out)))


from bisect import *
import itertools

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return a[i]
	raise ValueError

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return a[i]
	raise ValueError
t = int(input())
for _ in range(t):
	(nr, ng, nb) = map(int, input().split())
	r = list(map(int, input().split()))
	g = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r.sort()
	g.sort()
	b.sort()
	l = [r, g, b]
	best = 10 ** 20
	for (lo, mid, hi) in itertools.permutations([0, 1, 2]):
		for mid_el in l[mid]:
			try:
				lo_el = find_le(l[lo], mid_el)
				hi_el = find_ge(l[hi], mid_el)
				total = (mid_el - hi_el) ** 2 + (mid_el - lo_el) ** 2 + (hi_el - lo_el) ** 2
				best = min(best, total)
			except:
				pass
	print(best)


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor, ceil
from bisect import bisect_left as l_bound
from collections import Counter
from math import gcd
mod = 10 ** 9 + 7

def main():
	for _ in range(int(input())):
		(a, b, c) = map(int, input().split())
		ar_a = list(map(int, input().split()))
		ar_b = list(map(int, input().split()))
		ar_c = list(map(int, input().split()))
		ar_b.sort()
		ar_c.sort()
		ar_a.sort()
		ans = float('inf')
		for el in ar_c:
			ind1 = l_bound(ar_a, el)
			ind2 = l_bound(ar_b, el)
			for i in range(max(0, ind1 - 1), min(a, ind1 + 1)):
				for j in range(max(0, ind2 - 1), min(b, ind2 + 1)):
					ans = min(ans, (ar_a[i] - ar_b[j]) ** 2 + (ar_b[j] - el) ** 2 + (ar_a[i] - el) ** 2)
		(ar_c, ar_a) = (ar_a, ar_c)
		(c, a) = (a, c)
		for el in ar_c:
			ind1 = l_bound(ar_a, el)
			ind2 = l_bound(ar_b, el)
			for i in range(max(0, ind1 - 1), min(a, ind1 + 1)):
				for j in range(max(0, ind2 - 1), min(b, ind2 + 1)):
					ans = min(ans, (ar_a[i] - ar_b[j]) ** 2 + (ar_b[j] - el) ** 2 + (ar_a[i] - el) ** 2)
		(ar_c, ar_b) = (ar_b, ar_c)
		(c, b) = (b, c)
		for el in ar_c:
			ind1 = l_bound(ar_a, el)
			ind2 = l_bound(ar_b, el)
			for i in range(max(0, ind1 - 1), min(a, ind1 + 1)):
				for j in range(max(0, ind2 - 1), min(b, ind2 + 1)):
					ans = min(ans, (ar_a[i] - ar_b[j]) ** 2 + (ar_b[j] - el) ** 2 + (ar_a[i] - el) ** 2)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())

def f(arr, n):
	i = 0
	j = len(arr) - 1
	if len(arr) == 1:
		return arr[0]
	while i < j:
		mid = (i + j) // 2
		if i == mid and j == mid + 1:
			if abs(arr[i] - n) <= abs(arr[j] - n):
				return arr[i]
			else:
				return arr[j]
		elif arr[mid] > n:
			j = mid
		else:
			i = mid
for x in range(t):
	(r, g, b) = list(map(int, input().split()))
	rl = sorted(list(map(int, input().split())))
	rg = sorted(list(map(int, input().split())))
	rb = sorted(list(map(int, input().split())))
	result = 10 ** 36
	for aq in range(r):
		x = f(rg, rl[aq])
		y = f(rb, rl[aq])
		z = rl[aq]
		ns = (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2
		result = min(result, ns)
	for aq in range(g):
		x = f(rl, rg[aq])
		y = f(rb, rg[aq])
		z = rg[aq]
		ns = (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2
		result = min(result, ns)
	for aq in range(b):
		x = f(rl, rb[aq])
		y = f(rg, rb[aq])
		z = rb[aq]
		ns = (x - y) ** 2 + (y - z) ** 2 + (x - z) ** 2
		result = min(result, ns)
	print(result)