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
Tags: Sorting

Amortized analysis

Mathematics

Greedy algorithms
Skill types: Sorting

Amortized analysis

Greedy algorithms

Starter code:

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 math
import sys

def F(a, b, c):
	return (a - b) * (a - b) + (a - c) * (a - c) + (b - c) * (b - c)
t = int(input())
maxx = 10000000000000000000000000
for _ 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()
	x = 0
	y = 0
	z = 0
	ans = maxx
	while x < R - 1 or y < G - 1 or z < B - 1:
		ans = min(ans, F(r[x], g[y], b[z]))
		d1 = maxx
		d2 = maxx
		d3 = maxx
		if x < R - 1:
			d1 = F(r[x + 1], g[y], b[z])
		if y < G - 1:
			d2 = F(r[x], g[y + 1], b[z])
		if z < B - 1:
			d3 = F(r[x], g[y], b[z + 1])
		if d1 <= d2 and d1 <= d3:
			x += 1
		elif d2 <= d1 and d2 <= d3:
			y += 1
		else:
			z += 1
	ans = min(ans, F(r[x], g[y], b[z]))
	print(ans)


from bisect import bisect_left

def cal(l, m, s):
	return (m - l) ** 2 + (l - s) ** 2 + (m - s) ** 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]
		inx = bisect_left(S, m + 1)
		if inx == 0:
			continue
		s = S[inx - 1]
		ans = min(ans, cal(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]
		inx = bisect_left(S, m + 1)
		if inx == 0:
			continue
		s = S[inx - 1]
		ans = min(ans, cal(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]
		inx = bisect_left(S, m + 1)
		if inx == 0:
			continue
		s = S[inx - 1]
		ans = min(ans, cal(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]
		inx = bisect_left(S, m + 1)
		if inx == 0:
			continue
		s = S[inx - 1]
		ans = min(ans, cal(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]
		inx = bisect_left(S, m + 1)
		if inx == 0:
			continue
		s = S[inx - 1]
		ans = min(ans, cal(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]
		inx = bisect_left(S, m + 1)
		if inx == 0:
			continue
		s = S[inx - 1]
		ans = min(ans, cal(l, m, s))
	print(ans)


import bisect
import math

def solve(a, b, c):
	ans = float('inf')
	for i in b:
		if a[0] > i or c[-1] < i:
			continue
		mx = bisect.bisect_right(a, i) - 1
		mz = bisect.bisect_left(c, i)
		minn = (i - a[mx]) ** 2 + (i - c[mz]) ** 2 + (a[mx] - c[mz]) ** 2
		if minn < ans:
			ans = minn
	return ans
t = int(input())
for i in range(t):
	(x, y, z) = 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())))
	print(min(solve(r, g, b), solve(b, g, r), solve(r, b, g), solve(g, b, r), solve(g, r, b), solve(b, r, g)))


from math import ceil, log2
from collections import deque
from sys import stdin
from bisect import bisect_left as lower
input = stdin.readline

def read():
	return [int(i) for i in input().split()]

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

def run(a, b, c):
	ans = int(2e+18)
	for i in b:
		x = lower(a, i)
		y = lower(c, i)
		x = [a[x - 1]] if x == len(a) else [a[x]] if x == 0 else [a[x], a[x - 1]]
		y = [c[y - 1]] if y == len(c) else [c[y]] if y == 0 else [c[y], c[y - 1]]
		for u in x:
			for v in y:
				ans = min(ans, find(u, i, v))
	return ans
t = int(input())
for i in range(t):
	(n, m, p) = read()
	(a, b, c) = (list(read()), list(read()), list(read()))
	a.sort()
	b.sort()
	c.sort()
	ans = min(run(a, b, c), run(b, c, a), run(c, a, b))
	print(ans)


import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
for t in range(T):
	(a, b, c) = map(int, lines[4 * t + 1].strip().split(' '))
	As = list(map(int, lines[4 * t + 2].strip().split(' ')))
	Bs = list(map(int, lines[4 * t + 3].strip().split(' ')))
	Cs = list(map(int, lines[4 * t + 4].strip().split(' ')))
	As.sort()
	Bs.sort()
	Cs.sort()

	def solve(arr1, arr2, arr3):
		(L1, L2, L3) = (len(arr1), len(arr2), len(arr3))
		pt1 = 0
		pt2 = 0
		minDiff = 3 * 10 ** 18
		for i in range(L3):
			if pt1 >= L1 or pt2 >= L2:
				break
			num = arr3[i]
			while pt2 < L2 and arr2[pt2] < num:
				pt2 += 1
			if pt2 >= L2:
				break
			if arr1[pt1] > num:
				continue
			while pt1 + 1 < L1 and arr1[pt1 + 1] <= num:
				pt1 += 1
			minDiff = min(minDiff, (num - arr1[pt1]) ** 2 + (num - arr2[pt2]) ** 2 + (arr1[pt1] - arr2[pt2]) ** 2)
		return minDiff
	minDiff = min(solve(As, Bs, Cs), solve(As, Cs, Bs), solve(Bs, Cs, As), solve(Bs, As, Cs), solve(Cs, As, Bs), solve(Cs, Bs, As))
	print(minDiff)


import sys, bisect
input = sys.stdin.readline
for _ in range(int(input())):
	input()
	R = sorted(list(map(int, input().split())))
	G = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())))
	best = 10 ** 24
	for (r, g, b) in ((R, G, B), (G, R, B), (B, G, R)):
		for x in r:
			i = bisect.bisect(g, x)
			y = g[i] if i < len(g) and (x - g[i]) ** 2 < (x - g[i - 1]) ** 2 else g[i - 1]
			i = bisect.bisect(b, x)
			z = b[i] if i < len(b) and (x - b[i]) ** 2 < (x - b[i - 1]) ** 2 else b[i - 1]
			best = min(best, (x - y) ** 2 + (x - z) ** 2 + (y - z) ** 2)
	print(best)


import bisect

def getMin(a, b, c, la, lc):
	ans = float('inf')
	for i in b:
		ia = bisect.bisect_left(a, i)
		ic = bisect.bisect_right(c, i)
		if ia == la:
			ia -= 1
		if ic != 0:
			ic -= 1
		a1 = a[ia]
		c1 = c[ic]
		ans = min(ans, pow(i - a1, 2) + pow(i - c1, 2) + pow(a1 - c1, 2))
	return ans
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())))
	ans = float('inf')
	ans = min(ans, getMin(r, g, b, nr, nb))
	ans = min(ans, getMin(r, b, g, nr, ng))
	ans = min(ans, getMin(g, r, b, ng, nb))
	ans = min(ans, getMin(g, b, r, ng, nr))
	ans = min(ans, getMin(b, r, g, nb, ng))
	ans = min(ans, getMin(b, g, r, nb, nr))
	print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def calc(j, lis1, lis2):
	a = 0
	arr = []
	for i in lis1:
		for k in lis2:
			arr.append(pow(j - i, 2) + pow(i - k, 2) + pow(k - j, 2))
			a += 1
	if a == 0:
		return -1
	return min(arr)

def binarySearchLeft(arr, l, r, x):
	temp = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			temp = mid
			l = mid + 1
		else:
			r = mid - 1
	return temp

def binarySearchRight(arr, l, r, x):
	temp = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			temp = mid
			r = mid - 1
		else:
			l = mid + 1
	return temp
t = int(input())
for _ in range(t):
	(x, y, z) = list(map(int, input().split()))
	r = list(map(int, input().split()))
	g = list(map(int, input().split()))
	b = list(map(int, input().split()))
	lis = [0, 1, 2]
	r.sort()
	g.sort()
	b.sort()
	arr = [r, g, b]
	len1 = [len(r), len(g), len(b)]
	ans = 3 * pow(10, 18)
	for i in lis:
		l = len1[i]
		m = len1[(i + 1) % 3]
		n = len1[(i + 2) % 3]
		num = {}
		for j in range(l):
			lis1 = []
			lis2 = []
			temp1 = binarySearchRight(arr[(i + 1) % 3], 0, m - 1, arr[i][j])
			temp2 = binarySearchRight(arr[(i + 2) % 3], 0, n - 1, arr[i][j])
			temp3 = binarySearchLeft(arr[(i + 1) % 3], 0, m - 1, arr[i][j])
			temp4 = binarySearchLeft(arr[(i + 2) % 3], 0, n - 1, arr[i][j])
			if temp1 != -1:
				lis1.append(arr[(i + 1) % 3][temp1])
			if temp2 != -1:
				lis2.append(arr[(i + 2) % 3][temp2])
			if temp3 != -1:
				lis1.append(arr[(i + 1) % 3][temp3])
			if temp4 != -1:
				lis2.append(arr[(i + 2) % 3][temp4])
			num[arr[i][j]] = [lis1, lis2]
		for j in num.keys():
			temp = calc(j, num[j][0], num[j][1])
			if temp != -1:
				ans = min(ans, temp)
	print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().split()]

def st():
	return input()

def val():
	return int(input())

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def give(a, b, c):
	return (a - b) ** 2 + (b - c) ** 2 + (c - a) ** 2
for _ in range(val()):
	(n1, n2, n3) = li()
	l1 = sorted(li())
	l2 = sorted(li())
	l3 = sorted(li())
	l1.append(float('inf'))
	l2.append(float('inf'))
	l3.append(float('inf'))
	i = j = k = 0
	ans = give(l1[i], l2[j], l3[k])
	try:
		while i + j + k < n1 + n2 + n3:
			temp1 = give(l1[i + 1], l2[j], l3[k])
			temp2 = give(l1[i], l2[j + 1], l3[k])
			temp3 = give(l1[i], l2[j], l3[k + 1])
			curr = min(temp1, temp2, temp3)
			if curr == temp1:
				i += 1
			elif curr == temp2:
				j += 1
			else:
				k += 1
			ans = min(curr, ans)
		print(ans)
	except:
		print(ans)


import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def solve(a, b, c):
	ans = float('inf')
	for x in a:
		y = bisect.bisect_left(b, x)
		if y == len(b):
			continue
		y = b[y]
		z = bisect.bisect_left(c, x + 1)
		if z == 0:
			continue
		z = c[z - 1]
		ans = min(ans, work(x, y, z))
	return ans
for _ in range(iinput()):
	(x, y, z) = rinput()
	a = sorted(rlinput())
	b = sorted(rlinput())
	c = sorted(rlinput())
	ans = min(solve(a, b, c), solve(a, c, b), solve(b, c, a), solve(b, a, c), solve(c, b, a), solve(c, a, b))
	print(ans)


from bisect import bisect_left as bl

def take_closest(mylist, mynumber):
	pos = bl(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 t in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	(a, b, c) = (sorted(list(map(int, input().split()))) for _ in range(3))
	ans = []
	for x in a:
		y = take_closest(b, x)
		z = take_closest(c, x)
		ans.append((x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	for x in b:
		y = take_closest(a, x)
		z = take_closest(c, x)
		ans.append((x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	for x in c:
		y = take_closest(b, x)
		z = take_closest(a, x)
		ans.append((x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	print(min(ans))


import bisect

def left(arr, x):
	pos = bisect.bisect_right(arr, x)
	if pos == 0:
		return arr[0]
	return arr[pos - 1]

def right(arr, x):
	pos = bisect.bisect_left(arr, x)
	if pos >= len(arr) - 1:
		return arr[-1]
	return arr[pos]

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

def sol(R, G, B):
	minsum = 10 ** 20
	for i in range(len(G)):
		x = G[i]
		y = left(R, x)
		z = right(B, x)
		count = sums(x, y, z)
		if count < minsum:
			minsum = count
	return minsum
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()
	print(min(sol(R, G, B), sol(B, G, R), sol(G, R, B), sol(B, R, G), sol(R, B, G), sol(G, B, R)))


from bisect import bisect_left
from bisect import bisect_right

def lessnum(myList, myNumber):
	pos = bisect_right(myList, myNumber)
	if pos == 0:
		return myList[0]
	before = myList[pos - 1]
	return before

def morenum(a, key):
	i = bisect_left(a, key)
	if i == len(a):
		return a[-1]
	return a[i]
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()
	minsum = float('inf')
	for i in range(nr):
		x = R[i]
		y1 = morenum(G, x)
		z1 = lessnum(B, x)
		sums1 = (x - y1) ** 2 + (y1 - z1) ** 2 + (z1 - x) ** 2
		z2 = morenum(B, x)
		y2 = lessnum(G, x)
		sums2 = (x - y2) ** 2 + (y2 - z2) ** 2 + (z2 - x) ** 2
		if min(sums1, sums2) < minsum:
			minsum = min(sums1, sums2)
	for i in range(ng):
		x = G[i]
		y1 = morenum(R, x)
		z1 = lessnum(B, x)
		sums1 = (x - y1) ** 2 + (y1 - z1) ** 2 + (z1 - x) ** 2
		z2 = morenum(B, x)
		y2 = lessnum(R, x)
		sums2 = (x - y2) ** 2 + (y2 - z2) ** 2 + (z2 - x) ** 2
		if min(sums1, sums2) < minsum:
			minsum = min(sums1, sums2)
	for i in range(nb):
		x = B[i]
		y1 = morenum(R, x)
		z1 = lessnum(G, x)
		sums1 = (x - y1) ** 2 + (y1 - z1) ** 2 + (z1 - x) ** 2
		z2 = morenum(G, x)
		y2 = lessnum(R, x)
		sums2 = (x - y2) ** 2 + (y2 - z2) ** 2 + (z2 - x) ** 2
		if min(sums1, sums2) < minsum:
			minsum = min(sums1, sums2)
	print(minsum)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.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(io.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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
min2 = lambda x, y: x if x < y else y
inf = 1 << 62
inf1 = 10 ** 9 * 2
inf2 = -10 ** 9
inf3 = -10 ** 9 * 2
s = 0
for _ in range(T):
	(NR, NG, NB) = map(int, input().split())
	N = NR + NG + NB
	R = map(int, input().split())
	G = map(int, input().split())
	B = map(int, input().split())
	RGB = sorted([r << 2 for r in R] + [g << 2 | 1 for g in G] + [b << 2 | 2 for b in B])
	R1 = [inf1] * (N + 1)
	G1 = [inf2] * (N + 1)
	B1 = [inf3] * (N + 1)
	(r1, g1, b1) = (inf1, inf2, inf3)
	for (i, val_color) in enumerate(RGB, 1):
		(val, color) = (val_color >> 2, val_color & 3)
		if color == 0:
			r1 = val
		elif color == 1:
			g1 = val
		else:
			b1 = val
		R1[i] = r1
		G1[i] = g1
		B1[i] = b1
	(r2, g2, b2) = (inf1, inf2, inf3)
	ans = inf
	for (val_color, r1, g1, b1) in zip(RGB[::-1], R1[-2::-1], G1[-2::-1], B1[-2::-1]):
		(val, color) = (val_color >> 2, val_color & 3)
		if color == 0:
			r2 = val
			ans = min2(ans, min((r2 - g1) * (r2 - g1) + (g1 - b1) * (g1 - b1) + (b1 - r2) * (b1 - r2), (r2 - g1) * (r2 - g1) + (g1 - b2) * (g1 - b2) + (b2 - r2) * (b2 - r2), (r2 - g2) * (r2 - g2) + (g2 - b1) * (g2 - b1) + (b1 - r2) * (b1 - r2), (r2 - g2) * (r2 - g2) + (g2 - b2) * (g2 - b2) + (b2 - r2) * (b2 - r2)))
		elif color == 1:
			g2 = val
			ans = min2(ans, min((r1 - g2) * (r1 - g2) + (g2 - b1) * (g2 - b1) + (b1 - r1) * (b1 - r1), (r1 - g2) * (r1 - g2) + (g2 - b2) * (g2 - b2) + (b2 - r1) * (b2 - r1), (r2 - g2) * (r2 - g2) + (g2 - b1) * (g2 - b1) + (b1 - r2) * (b1 - r2), (r2 - g2) * (r2 - g2) + (g2 - b2) * (g2 - b2) + (b2 - r2) * (b2 - r2)))
		else:
			b2 = val
			ans = min2(ans, min((r1 - g1) * (r1 - g1) + (g1 - b2) * (g1 - b2) + (b2 - r1) * (b2 - r1), (r1 - g2) * (r1 - g2) + (g2 - b2) * (g2 - b2) + (b2 - r1) * (b2 - r1), (r2 - g1) * (r2 - g1) + (g1 - b2) * (g1 - b2) + (b2 - r2) * (b2 - r2), (r2 - g2) * (r2 - g2) + (g2 - b2) * (g2 - b2) + (b2 - r2) * (b2 - r2)))
	print(ans)


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())


from bisect import bisect_left

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

def nearest(r, x):
	yi = bisect_left(r, x)
	if yi == 0:
		y = r[0]
	elif yi == len(r):
		y = r[-1]
	else:
		y = r[yi] if r[yi] - x < x - r[yi - 1] else r[yi - 1]
	return y
T = int(input())
for _ in range(T):
	l = list(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()
	ans = []
	for (r, g, b) in ((R, G, B), (R, B, G), (B, R, G)):
		for x in g:
			y = nearest(r, x)
			z = nearest(b, x)
			ans.append(calc(x, y, z))
	print(min(ans))


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		(n_r, n_g, n_b) = get_int_input_arr()
		r_arr = get_int_input_arr()
		g_arr = get_int_input_arr()
		b_arr = get_int_input_arr()
		r_arr.sort()
		g_arr.sort()
		b_arr.sort()
		(ptr_1, ptr_2, ptr_3) = (0, 0, 0)
		res = float('inf')

		def calc(p1, p2, p3):
			return (r_arr[p1] - g_arr[p2]) ** 2 + (g_arr[p2] - b_arr[p3]) ** 2 + (b_arr[p3] - r_arr[p1]) ** 2
		while ptr_1 < n_r and ptr_2 < n_g and (ptr_3 < n_b):
			res = min(res, calc(ptr_1, ptr_2, ptr_3))
			move = [0] * 3
			min_can = float('inf')
			min_p = -1
			if ptr_1 < n_r - 1:
				c = calc(ptr_1 + 1, ptr_2, ptr_3)
				if min_can > c:
					min_can = c
					min_p = 1
			if ptr_2 < n_g - 1:
				c = calc(ptr_1, ptr_2 + 1, ptr_3)
				if min_can > c:
					min_can = c
					min_p = 2
			if ptr_3 < n_b - 1:
				c = calc(ptr_1, ptr_2, ptr_3 + 1)
				if min_can > c:
					min_can = c
					min_p = 3
			if min_p == 1:
				ptr_1 += 1
			if min_p == 2:
				ptr_2 += 1
			if min_p == 3:
				ptr_3 += 1
			if min_p == -1:
				break
		cout << res << endl

def main():
	solve()
main()


import sys
input = sys.stdin.readline

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

def match(a, b, c):

	def calculate_result(result, item1, item2, item3):
		return min(result, (item1 - item2) ** 2 + (item2 - item3) ** 2 + (item1 - item3) ** 2)
	len_a = len(a)
	len_b = len(b)
	len_c = len(c)
	a.sort(reverse=False)
	b.sort(reverse=False)
	c.sort(reverse=False)
	result = 10 ** 99
	index_b = 0
	index_c = 0
	for item in a:
		(index_b, index_c) = search(item, b, c, index_b, index_c)
		result = calculate_result(result, item, b[index_b], c[index_c])
		if index_c < len_c - 1:
			result = calculate_result(result, item, b[index_b], c[index_c + 1])
		if index_b < len_b - 1:
			result = calculate_result(result, item, b[index_b + 1], c[index_c])
	return result

def search(item, b, c, index_b, index_c):
	len_b = len(b)
	len_c = len(c)
	while b[index_b] <= item:
		index_b += 1
		if len_b == index_b:
			break
	while c[index_c] <= item:
		index_c += 1
		if len_c == index_c:
			break
	return (max(0, index_b - 1), max(0, index_c - 1))
cases = int(input())
for case in range(cases):
	inlt()
	a = inlt()
	b = inlt()
	c = inlt()
	result = min(match(a, b, c), match(b, c, a), match(c, a, b))
	sys.__stdout__.write(str(result) + '\n')


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 os
import sys
input = sys.stdin.buffer.readline
from collections import deque
from queue import PriorityQueue
import math

class CF(object):

	def __init__(self):
		t = int(input())
		for _ in range(t):
			(na, nb, nc) = list(map(int, input().split()))
			a = list(map(int, input().split()))
			b = list(map(int, input().split()))
			c = list(map(int, input().split()))
			a.sort()
			b.sort()
			c.sort()
			ans = int(1e+22)
			for now in a:
				x = self.find(b, now)
				y = self.find(c, now)
				ans = min(ans, self.f(x, y))
			pass
			for now in b:
				x = self.find(a, now)
				y = self.find(c, now)
				ans = min(ans, self.f(x, y))
			pass
			for now in c:
				x = self.find(a, now)
				y = self.find(b, now)
				ans = min(ans, self.f(x, y))
			pass
			print(ans)
		pass

	def find(self, a, x):
		l = 0
		r = len(a) - 1
		while l < r:
			mid = int((l + r + 1) // 2)
			if a[mid] < x:
				l = mid
			else:
				r = mid - 1
		pass
		return min(abs(a[l] - x), abs(a[(l + 1) % len(a)] - x))

	def f(self, x, y):
		return int(x * x + y * y + (x + y) ** 2)

	def main(self):
		pass
cf = CF()
cf.main()
pass


t = int(input())
for u in range(t):
	(a, b, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	for i in range(len(a)):
		a[i] = [a[i], 0]
	for i in range(len(b)):
		b[i] = [b[i], 1]
	for i in range(len(c)):
		c[i] = [c[i], 2]
	a.extend(b)
	a.extend(c)
	a.sort(key=lambda x: x[0])
	maxi = float('inf')
	start = 0
	end = 0
	dic = {0: -1, 1: -1, 2: -1}
	while end < len(a):
		dic[a[end][1]] = end
		if dic[0] != -1 and dic[1] != -1 and (dic[2] != -1):
			if dic[0] == start:
				dic[0] = -1
			if dic[1] == start:
				dic[1] = -1
			if dic[2] == start:
				dic[2] = -1
			start += 1
			if dic[0] == -1 or dic[1] == -1 or dic[2] == -1:
				for i in range(start, end):
					temp = (a[start - 1][0] - a[i][0]) ** 2 + (a[start - 1][0] - a[end][0]) ** 2 + (a[end][0] - a[i][0]) ** 2
					if temp < maxi:
						maxi = temp
		else:
			end += 1
	print(maxi)


import bisect
testCases = int(input())

def f1(x, y, z):
	global ans
	for t1 in y:
		x_val = 0
		ind1 = bisect.bisect_left(x, t1)
		if ind1 == len(x):
			x_val = x[ind1 - 1]
		elif ind1 == 0:
			if x[ind1] == t1:
				x_val = x[ind1]
			else:
				continue
		elif x[ind1] == t1:
			x_val = x[ind1]
		else:
			x_val = x[ind1 - 1]
		z_val = 0
		ind2 = bisect.bisect_left(z, t1)
		if ind2 == len(z):
			continue
		else:
			z_val = z[ind2]
		val = (t1 - x_val) ** 2 + (t1 - z_val) ** 2 + (z_val - x_val) ** 2
		if val < ans:
			ans = val
for i1 in range(testCases):
	(nr, ng, nb) = list(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())))
	ans = 9e+18
	f1(r, g, b)
	f1(r, b, g)
	f1(g, r, b)
	f1(g, b, r)
	f1(b, g, r)
	f1(b, r, g)
	print(ans)


import bisect
from itertools import permutations
get_value = lambda a, b, c: (a - b) ** 2 + (b - c) ** 2 + (c - a) ** 2

def find_min(a, b, c):
	v = float('inf')
	ia = 0
	ic = 0
	la = len(a)
	lc = len(c)
	for eb in b:
		ia = min(bisect.bisect_left(a, eb, ia), la - 1)
		ic = min(bisect.bisect_right(c, eb, ic), lc - 1)
		v = min(v, get_value(a[ia], eb, c[ic]), get_value(a[ia - 1], eb, c[ic]))
	return v

def solve(sr, sg, sb):
	if sr & sg & sb:
		return 0
	(ar, ag, ab) = map(sorted, (sr, sg, sb))
	v = float('inf')
	for (a, b, c) in permutations([ar, ag, ab]):
		v = min(v, find_min(a, b, c))
	return v
for _ in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	sr = set(map(int, input().split()))
	sg = set(map(int, input().split()))
	sb = set(map(int, input().split()))
	v = solve(sr, sg, sb)
	print(v)


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

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for i in range(int(input())):
	(r, g, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	fans = 99999999999999999999999999999999999999999999999999999
	l1.sort()
	l.sort()
	l2.sort()
	for i in range(r):
		f = countGreater(l1, g, l[i])
		f1 = binarySearchCount(l2, b, l[i])
		if f != 0 and f1 != 0:
			fans = min(fans, calc(l[i], l2[f1 - 1], l1[g - f]))
	for i in range(r):
		f = countGreater(l2, b, l[i])
		f1 = binarySearchCount(l1, g, l[i])
		if f != 0 and f1 != 0:
			fans = min(fans, calc(l[i], l1[f1 - 1], l2[b - f]))
	for i in range(g):
		f = countGreater(l, r, l1[i])
		f1 = binarySearchCount(l2, b, l1[i])
		if f != 0 and f1 != 0:
			fans = min(fans, calc(l1[i], l2[f1 - 1], l[r - f]))
	for i in range(g):
		f = countGreater(l2, b, l1[i])
		f1 = binarySearchCount(l, r, l1[i])
		if f != 0 and f1 != 0:
			fans = min(fans, calc(l1[i], l[f1 - 1], l2[b - f]))
	for i in range(b):
		f = countGreater(l, r, l2[i])
		f1 = binarySearchCount(l1, g, l2[i])
		if f != 0 and f1 != 0:
			fans = min(fans, calc(l2[i], l1[f1 - 1], l[r - f]))
	for i in range(b):
		f = countGreater(l1, g, l2[i])
		f1 = binarySearchCount(l, r, l2[i])
		if f != 0 and f1 != 0:
			fans = min(fans, calc(l2[i], l[f1 - 1], l1[g - f]))
	print(fans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
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 itertools import permutations
t = int(input())
for _ in range(t):
	res = None
	map(int, input().split())
	arr = []
	arr.append(sorted(map(int, input().split())))
	arr.append(sorted(map(int, input().split())))
	arr.append(sorted(map(int, input().split())))
	res = None
	for (b, m, l) in permutations([0, 1, 2]):
		(i, j, k) = (0, 0, 0)
		while j < len(arr[m]):
			while i + 1 < len(arr[b]) and arr[b][i] < arr[m][j]:
				i += 1
			while k + 1 < len(arr[l]) and arr[l][k + 1] <= arr[m][j]:
				k += 1
			last = [arr[b][i], arr[m][j], arr[l][k]]
			v = (last[0] - last[1]) ** 2 + (last[1] - last[2]) ** 2 + (last[0] - last[2]) ** 2
			if res is None or res > v:
				res = v
			j += 1
	print(res)


import os
import sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd, log
from collections import *
from bisect import *
from heapq import *
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')
g = lambda : input().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()

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

def solve(x, y, z):
	ans = inf
	for vx in x:
		if y[0] <= vx and z[-1] >= vx:
			ans = min(ans, cal(vx, y[bisect_right(y, vx) - 1], z[bisect_left(z, vx)]))
		if z[0] <= vx and y[-1] >= vx:
			ans = min(ans, cal(vx, z[bisect_right(z, vx) - 1], y[bisect_left(y, vx)]))
	return ans
for _ in range(t):
	g()
	(x, y, z) = (gil(), gil(), gil())
	x.sort()
	y.sort()
	z.sort()
	ans = min(solve(x, y, z), solve(x, z, y), solve(y, z, x), solve(y, x, z), solve(z, x, y), solve(z, y, x))
	print(ans)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve_impl(nr, ng, nb, r, g, b):
	ans = float('inf')
	for y in g:
		i = bisect.bisect_left(r, y)
		x = r[i] if i < nr and r[i] == y else r[max(i - 1, 0)]
		j = bisect.bisect_right(b, y - 1)
		j = min(j, nb - 1)
		z = b[j]
		ans = min(ans, (x - y) ** 2 + (y - z) ** 2 + (z - x) ** 2)
	return ans

def solve(nr, ng, nb, r, g, b):
	r.sort()
	g.sort()
	b.sort()
	va = solve_impl(nr, ng, nb, r, g, b)
	vb = solve_impl(ng, nr, nb, g, r, b)
	vc = solve_impl(nb, nr, ng, b, r, g)
	vd = solve_impl(nr, nb, ng, r, b, g)
	ve = solve_impl(ng, nb, nr, g, b, r)
	vf = solve_impl(nb, ng, nr, b, g, r)
	return min(va, vb, vc, vd, ve, vf)
T = int(input())
ans = []
for ti in range(T):
	(nr, ng, nb) = map(int, 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()]
	ans.append(solve(nr, ng, nb, r, g, b))
print('\n'.join(map(str, ans)))


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))


import sys
import math
import collections
import heapq
input = sys.stdin.readline
t = int(input())
for w in range(t):
	(r, g, b) = (int(i) for i in input().split())
	l1 = sorted([int(i) for i in input().split()])
	l2 = sorted([int(i) for i in input().split()])
	l3 = sorted([int(i) for i in input().split()])
	m = 10000000000000000000
	for i in range(g):
		le = 0
		ri = b - 1
		while le < ri:
			mid = (le + ri) // 2
			if l3[ri] <= l2[i]:
				le = ri
				break
			if l3[le] >= l2[i]:
				break
			if mid < b - 1 and l3[mid] <= l2[i] and (l3[mid + 1] > l2[i]):
				le = mid
				break
			elif l3[mid] == l2[i]:
				le = mid
				break
			elif l3[mid] < l2[i]:
				le = mid + 1
			elif l3[mid] > l2[i]:
				ri = mid - 1
		k1 = l3[le]
		le = 0
		ri = r - 1
		while le < ri:
			mid = (le + ri) // 2
			if l1[le] >= l2[i]:
				ri = le
				break
			if l1[ri] <= l2[i]:
				break
			if mid > 0 and l1[mid] >= l2[i] and (l1[mid - 1] < l2[i]):
				ri = mid
				break
			elif l1[mid] == l2[i]:
				ri = mid
				break
			elif l1[mid] < l2[i]:
				le = mid + 1
			elif l1[mid] > l2[i]:
				ri = mid - 1
		k2 = l1[ri]
		s = (k1 - k2) * (k1 - k2) + (l2[i] - k1) * (l2[i] - k1) + (l2[i] - k2) * (l2[i] - k2)
		m = min(m, s)
	for i in range(g):
		le = 0
		ri = r - 1
		while le < ri:
			mid = (le + ri) // 2
			if l1[ri] <= l2[i]:
				le = ri
				break
			if l1[le] >= l2[i]:
				break
			if mid < r - 1 and l1[mid] <= l2[i] and (l1[mid + 1] > l2[i]):
				le = mid
				break
			elif l1[mid] == l2[i]:
				le = mid
				break
			elif l1[mid] < l2[i]:
				le = mid + 1
			elif l1[mid] > l2[i]:
				ri = mid - 1
		k1 = l1[le]
		le = 0
		ri = b - 1
		while le < ri:
			mid = (le + ri) // 2
			if l3[le] >= l2[i]:
				ri = le
				break
			if l3[ri] <= l2[i]:
				break
			if mid > 0 and l3[mid] >= l2[i] and (l3[mid - 1] < l2[i]):
				ri = mid
				break
			elif l3[mid] == l2[i]:
				ri = mid
				break
			elif l3[mid] < l2[i]:
				le = mid + 1
			elif l3[mid] > l2[i]:
				ri = mid - 1
		k2 = l3[ri]
		s = (k1 - k2) * (k1 - k2) + (l2[i] - k1) * (l2[i] - k1) + (l2[i] - k2) * (l2[i] - k2)
		m = min(m, s)
	for i in range(r):
		le = 0
		ri = b - 1
		while le < ri:
			mid = (le + ri) // 2
			if l3[ri] <= l1[i]:
				le = ri
				break
			if l3[le] >= l1[i]:
				break
			if mid < b - 1 and l3[mid] <= l1[i] and (l3[mid + 1] > l1[i]):
				le = mid
				break
			elif l3[mid] == l1[i]:
				le = mid
				break
			elif l3[mid] < l1[i]:
				le = mid + 1
			elif l3[mid] > l1[i]:
				ri = mid - 1
		k1 = l3[le]
		le = 0
		ri = g - 1
		while le < ri:
			mid = (le + ri) // 2
			if l2[le] >= l1[i]:
				ri = le
				break
			if l2[ri] <= l1[i]:
				break
			if mid > 0 and l2[mid] >= l1[i] and (l2[mid - 1] < l1[i]):
				ri = mid
				break
			elif l2[mid] == l1[i]:
				ri = mid
				break
			elif l2[mid] < l1[i]:
				le = mid + 1
			elif l2[mid] > l1[i]:
				ri = mid - 1
		k2 = l2[ri]
		s = (k1 - k2) * (k1 - k2) + (l1[i] - k1) * (l1[i] - k1) + (l1[i] - k2) * (l1[i] - k2)
		m = min(m, s)
	for i in range(r):
		le = 0
		ri = g - 1
		while le < ri:
			mid = (le + ri) // 2
			if l2[ri] <= l1[i]:
				le = ri
				break
			if l2[le] >= l1[i]:
				break
			if mid < g - 1 and l2[mid] <= l1[i] and (l2[mid + 1] > l1[i]):
				le = mid
				break
			elif l2[mid] == l1[i]:
				le = mid
				break
			elif l2[mid] < l1[i]:
				le = mid + 1
			elif l2[mid] > l1[i]:
				ri = mid - 1
		k1 = l2[le]
		le = 0
		ri = b - 1
		while le < ri:
			mid = (le + ri) // 2
			if l3[le] >= l1[i]:
				ri = le
				break
			if l3[ri] <= l1[i]:
				break
			if mid > 0 and l3[mid] >= l1[i] and (l3[mid - 1] < l1[i]):
				ri = mid
				break
			elif l3[mid] == l1[i]:
				ri = mid
				break
			elif l3[mid] < l1[i]:
				le = mid + 1
			elif l3[mid] > l1[i]:
				ri = mid - 1
		k2 = l3[ri]
		s = (k1 - k2) * (k1 - k2) + (l1[i] - k1) * (l1[i] - k1) + (l1[i] - k2) * (l1[i] - k2)
		m = min(m, s)
	for i in range(b):
		le = 0
		ri = r - 1
		while le < ri:
			mid = (le + ri) // 2
			if l1[ri] <= l3[i]:
				le = ri
				break
			if l1[le] >= l3[i]:
				break
			if mid < r - 1 and l1[mid] <= l3[i] and (l1[mid + 1] > l3[i]):
				le = mid
				break
			elif l1[mid] == l3[i]:
				le = mid
				break
			elif l1[mid] < l3[i]:
				le = mid + 1
			elif l1[mid] > l3[i]:
				ri = mid - 1
		k1 = l1[le]
		le = 0
		ri = g - 1
		while le < ri:
			mid = (le + ri) // 2
			if l2[le] >= l3[i]:
				ri = le
				break
			if l2[ri] <= l3[i]:
				break
			if mid > 0 and l2[mid] >= l3[i] and (l2[mid - 1] < l3[i]):
				ri = mid
				break
			elif l2[mid] == l3[i]:
				ri = mid
				break
			elif l2[mid] < l3[i]:
				le = mid + 1
			elif l2[mid] > l3[i]:
				ri = mid - 1
		k2 = l2[ri]
		s = (k1 - k2) * (k1 - k2) + (l3[i] - k1) * (l3[i] - k1) + (l3[i] - k2) * (l3[i] - k2)
		m = min(m, s)
	for i in range(b):
		le = 0
		ri = g - 1
		while le < ri:
			mid = (le + ri) // 2
			if l2[ri] <= l3[i]:
				le = ri
				break
			if l2[le] >= l3[i]:
				break
			if mid < g - 1 and l2[mid] <= l3[i] and (l2[mid + 1] > l3[i]):
				le = mid
				break
			elif l2[mid] == l3[i]:
				le = mid
				break
			elif l2[mid] < l3[i]:
				le = mid + 1
			elif l2[mid] > l3[i]:
				ri = mid - 1
		k1 = l2[le]
		le = 0
		ri = r - 1
		while le < ri:
			mid = (le + ri) // 2
			if l1[le] >= l3[i]:
				ri = le
				break
			if l1[ri] <= l3[i]:
				break
			if mid > 0 and l1[mid] >= l3[i] and (l1[mid - 1] < l3[i]):
				ri = mid
				break
			elif l1[mid] == l3[i]:
				ri = mid
				break
			elif l1[mid] < l3[i]:
				le = mid + 1
			elif l1[mid] > l3[i]:
				ri = mid - 1
		k2 = l1[ri]
		s = (k1 - k2) * (k1 - k2) + (l3[i] - k1) * (l3[i] - k1) + (l3[i] - k2) * (l3[i] - k2)
		m = min(m, s)
	print(m)


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()


for _ in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	rs = list(map(int, input().split()))
	gs = list(map(int, input().split()))
	bs = list(map(int, input().split()))
	rs.sort()
	gs.sort()
	bs.sort()
	t = []
	for c in rs:
		t.append((c, 1))
	for c in gs:
		t.append((c, 2))
	for c in bs:
		t.append((c, 3))
	t.sort()
	(left, right, cnt) = (0, 0, 0)
	mp = [0] * 4
	ans = float('inf')

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

	def f2(arr):
		res = float('inf')
		a = arr[0][0]
		c = arr[-1][0]
		for i in range(1, len(arr) - 1):
			if arr[i][1] != arr[0][1] and arr[i][1] != arr[-1][1]:
				res = min(res, f(a, arr[i][0], c))
		return res
	while right < len(t):
		mp[t[right][1]] += 1
		if mp[t[right][1]] == 1:
			cnt += 1
		right += 1
		while cnt == 3:
			if mp[t[left][1]] == 1:
				ans = min(ans, f2(t[left:right]))
			mp[t[left][1]] -= 1
			if mp[t[left][1]] == 0:
				cnt -= 1
			left += 1
	print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from bisect import bisect_right, bisect_left
t = int(input())

def calc(red, green, blue):
	mn = 10 ** 20
	r = len(red)
	g = len(green)
	b = len(blue)
	for red_element in red:
		blue_element = bisect_right(blue, red_element) - 1
		green_element = bisect_left(green, red_element)
		if blue_element == -1:
			blue_element += 1
		if green_element == g:
			green_element -= 1
		blue_element = blue[blue_element]
		green_element = green[green_element]
		mn = min(mn, (red_element - blue_element) ** 2 + (blue_element - green_element) ** 2 + (green_element - red_element) ** 2)
	return mn
for _ in range(t):
	(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()
	print(min(calc(red, green, blue), calc(red, blue, green), calc(blue, red, green), calc(blue, green, red), calc(green, red, blue), calc(green, blue, red)))


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
import sys
input = sys.stdin.readline
t = int(input())

def poschecker(l, n):
	pos = bisect_left(l, n)
	if pos == 0:
		return l[0]
	elif pos == len(l):
		return l[-1]
	elif n - l[pos - 1] < l[pos] - n:
		return l[pos - 1]
	else:
		return l[pos]
for i in range(t):
	(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()
	(ansr, ansg, ansb) = ([], [], [])
	for x in r:
		a = poschecker(g, x)
		z = poschecker(b, x)
		ansr.append((a - z) ** 2 + (a - x) ** 2 + (z - x) ** 2)
	ans1 = min(ansr)
	for x in g:
		a = poschecker(r, x)
		z = poschecker(b, x)
		ansg.append((a - z) ** 2 + (a - x) ** 2 + (z - x) ** 2)
	ans2 = min(ansg)
	for x in b:
		a = poschecker(g, x)
		z = poschecker(r, x)
		ansb.append((a - z) ** 2 + (a - x) ** 2 + (z - x) ** 2)
	ans3 = min(ansb)
	sys.stdout.write(str(min(ans1, ans2, ans3)) + '\n')


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)


import sys
import bisect
input = sys.stdin.readline

def solve(r, g, b):
	ans = 3 * 10 ** 18
	for i in g:
		r1 = bisect.bisect_right(r, i)
		r2 = bisect.bisect_left(b, i)
		if r1 == 0 or r2 == len(b):
			continue
		j = r[r1 - 1]
		k = b[r2]
		ans = min(ans, (i - j) ** 2 + (j - k) ** 2 + (k - i) ** 2)
	return ans
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()
	ans = solve(r, g, b)
	ans = min(ans, solve(b, g, r))
	ans = min(ans, solve(g, r, b))
	ans = min(ans, solve(b, r, g))
	ans = min(ans, solve(g, b, r))
	ans = min(ans, solve(r, b, g))
	print(ans)


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)


def find(M, x):
	a = 0
	b = len(M) - 1
	while b - a > 1:
		if M[(a + b) // 2] > x:
			b = (a + b) // 2
		else:
			a = (a + b) // 2
	return b if M[b] <= x else a

def check(a, b, M):
	x = (a + b) / 2
	im = find(M, x)
	x = (a - b) ** 2 + (a - M[im]) ** 2 + (M[im] - b) ** 2
	return x if im == len(M) - 1 else min(x, (a - b) ** 2 + (a - M[im + 1]) ** 2 + (M[im + 1] - b) ** 2)
for t in range(int(input())):
	(nr, ng, nb) = map(int, input().split())
	red = sorted(list(map(int, input().split())))
	gre = sorted(list(map(int, input().split())))
	blu = sorted(list(map(int, input().split())))
	ans = 10 ** 22
	for i in range(nr):
		g = find(gre, red[i])
		b = find(blu, red[i])
		diffg = check(red[i], gre[g], blu)
		diffb = check(red[i], blu[b], gre)
		if g + 1 != len(gre):
			diffg = min(diffg, check(red[i], gre[g + 1], blu))
		if b + 1 != len(blu):
			diffb = min(diffb, check(red[i], blu[b + 1], gre))
		ans = min(ans, diffb, diffg)
	print(ans)


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()


from itertools import permutations

def min_val(rs, gs, bs):
	perm = permutations([0, 1, 2])
	(rs, gs, bs) = (list(sorted(rs)), list(sorted(gs)), list(sorted(bs)))
	nexts = [rs, gs, bs]
	best_so_far = (rs[0] - gs[0]) ** 2 + (rs[0] - bs[0]) ** 2 + (bs[0] - gs[0]) ** 2
	for p in perm:
		(c0, c1, c2) = (0, 0, 0)
		while True:
			if c0 < len(nexts[p[0]]) - 1 and nexts[p[0]][c0 + 1] <= nexts[p[1]][c1]:
				c0 += 1
			elif c1 < len(nexts[p[1]]) - 1 and nexts[p[1]][c1 + 1] <= nexts[p[2]][c2]:
				c1 += 1
			elif c2 < len(nexts[p[2]]) - 1:
				c2 += 1
			else:
				break
			at = (nexts[p[0]][c0] - nexts[p[1]][c1]) ** 2 + (nexts[p[0]][c0] - nexts[p[2]][c2]) ** 2 + (nexts[p[2]][c2] - nexts[p[1]][c1]) ** 2
			if at < best_so_far:
				best_so_far = at
	print(best_so_far)
t = int(input())
for i in range(t):
	(nr, ng, nb) = map(int, input().split())
	rs = map(int, input().split())
	gs = map(int, input().split())
	bs = map(int, input().split())
	min_val(rs, gs, bs)


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)