Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef decided to exercise by running somewhere from ShareChat. He chose three sets of points in a plane:
A set of $N$ points (numbered $1$ through $N$): for each valid $i$, the $i$-th of them has coordinates $(a_{i}, b_{i})$.
A set of $M$ points (numbered $1$ through $M$): for each valid $i$, the $i$-th of them has coordinates $(c_{i}, d_{i})$.
A set of $K$ points (numbered $1$ through $K$): for each valid $i$, the $i$-th of them has coordinates $(e_{i}, f_{i})$.

ShareChat has coordinates $(x, y)$. Chef must choose one point $(a_{j}, b_{j})$, one point $(c_{k}, d_{k})$, and one point $(e_{l}, f_{l})$. Then, he starts running from ShareChat, visits the chosen points $(a_{j}, b_{j})$ and $(c_{k}, d_{k})$ in any order, and then runs to the point $(e_{l}, f_{l})$, where he finishes his run.

Help Chef find the minimum distance he has to run.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $x$ and $y$.
The second line contains three space-separated integers $N$, $M$ and $K$.
The third line contains $2N$ space-separated integers $a_{1}, b_{1}, a_{2}, b_{2}, \ldots, a_{N}, b_{N}$.
The fourth line contains $2M$ space-separated integers $c_{1}, d_{1}, c_{2}, d_{2}, \ldots, c_{M}, d_{M}$.
The fifth line contains $2K$ space-separated integers $e_{1}, f_{1}, e_{2}, f_{2}, \ldots, e_{K}, f_{K}$.

------  Output ------
For each test case, print a single line containing one real number ― the minimum distance.

Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$.

------  Constraints  ------
$1 ≤ T ≤ 5,000$
$1 ≤ N, M, K ≤ 5,000$
$0 ≤ x, y ≤ 10^{9}$
$0 ≤ a_{i}, b_{i} ≤ 10^{9}$ for each valid $i$
$0 ≤ c_{i}, d_{i} ≤ 10^{9}$ for each valid $i$
$0 ≤ e_{i}, f_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N+M+K$ over all test cases does not exceed $15,000$

------  Subtasks ------
Subtask #1 (50 points): $1 ≤ N, M, K ≤ 100$

Subtask #2 (50 points): original constraints

----- Sample Input 1 ------ 
2
1 4
3 2 2
4 4 2 0 8 1
10 1 3 1
1 3 9 5
6 4
2 2 3
7 10 5 7
1 6 2 3
1 8 0 7 0 2
----- Sample Output 1 ------ 
8.1820424980
8.6995968482
----- explanation 1 ------ 
Example case 1:

- The black point is ShareChat,
- Points from the first set are red.
- Points from the second set are green.
- Points from the third set are blue.
- The black line corresponds to Chef's run.

Chef should run from $(1, 4)$ to $(3, 1)$, then to $(2, 0)$ and then to $(1, 3)$. The distance is $\sqrt{13}+\sqrt{2}+\sqrt{10} \doteq 8.1820424980$.

Example case 2:

Chef should run from $(6, 4)$ to $(5, 7)$, then to $(1, 6)$ and then to $(0, 7)$. The distance is $\sqrt{10}+\sqrt{17}+\sqrt{2} \doteq 8.6995968482$.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Dynamic programming


Solutions:
import math
for t in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = list(map(int, input().split()))
	l11 = []
	l22 = []
	l33 = []
	for i in range(0, 2 * n, 2):
		s = math.sqrt((x - l1[i]) ** 2 + (y - l1[i + 1]) ** 2)
		l11.append((s, (l1[i], l1[i + 1])))
	l11.sort(key=lambda x: x[0])
	for i in range(0, 2 * m, 2):
		s = math.sqrt((l11[0][1][0] - l2[i]) ** 2 + (l11[0][1][1] - l2[i + 1]) ** 2)
		l22.append((s, (l2[i], l2[i + 1])))
	l22.sort(key=lambda x: x[0])
	for i in range(0, 2 * k, 2):
		s = math.sqrt((l22[0][1][0] - l3[i]) ** 2 + (l22[0][1][1] - l3[i + 1]) ** 2)
		l33.append((s, (l3[i], l3[i + 1])))
	l33.sort(key=lambda x: x[0])
	ans1 = ans2 = 999999999999999999
	if n > 35:
		n = 35
	if m > 70:
		m = 70
	if k > 50:
		k = 50
	for i in range(0, n):
		s = math.sqrt((x - l11[i][1][0]) ** 2 + (y - l11[i][1][1]) ** 2)
		for j in range(0, m):
			s1 = s
			s += math.sqrt((l11[i][1][0] - l22[j][1][0]) ** 2 + (l11[i][1][1] - l22[j][1][1]) ** 2)
			for q in range(0, k):
				s2 = s
				s += math.sqrt((l22[j][1][0] - l33[q][1][0]) ** 2 + (l22[j][1][1] - l33[q][1][1]) ** 2)
				if s < ans1:
					ans1 = s
				s = s2
			s = s1
	for i in range(0, m):
		s = math.sqrt((x - l22[i][1][0]) ** 2 + (y - l22[i][1][1]) ** 2)
		for j in range(0, n):
			s1 = s
			s += math.sqrt((l22[i][1][0] - l11[j][1][0]) ** 2 + (l22[i][1][1] - l11[j][1][1]) ** 2)
			for q in range(0, k):
				s2 = s
				s += math.sqrt((l11[j][1][0] - l33[q][1][0]) ** 2 + (l11[j][1][1] - l33[q][1][1]) ** 2)
				if s < ans2:
					ans2 = s
				s = s2
			s = s1
	print(min(ans1, ans2))


def distance(c1, c2):
	(x, y) = c1
	(x1, y1) = c2
	dist = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
	return dist

def solve(x, y, ab, cd, ef):
	ans = float('inf')
	d = {}
	for a in ab:
		dist = distance((x, y), a)
		d[a] = dist
		if dist < ans:
			for c in cd:
				dist = distance(a, c) + d[a]
				d[c] = dist
				if dist < ans:
					for e in ef:
						dist = distance(c, e) + d[c]
						if dist < ans:
							ans = dist
	return ans
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	ab = [int(i) for i in input().split()]
	ab = [(ab[i], ab[i + 1]) for i in range(2 * n) if i % 2 == 0]
	cd = [int(i) for i in input().split()]
	cd = [(cd[i], cd[i + 1]) for i in range(2 * m) if i % 2 == 0]
	ef = [int(i) for i in input().split()]
	ef = [(ef[i], ef[i + 1]) for i in range(2 * k) if i % 2 == 0]
	ans1 = solve(x, y, ab, cd, ef)
	ans2 = solve(x, y, cd, ab, ef)
	print(min(ans1, ans2))


import sys
t = int(input())

def dist(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
while t:
	t -= 1
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	low = sys.maxsize
	for i in range(n):
		probable_low = dist(x, y, a[2 * i], a[2 * i + 1])
		if probable_low < low:
			for j in range(m):
				step1_low = probable_low + dist(a[2 * i], a[2 * i + 1], b[2 * j], b[j * 2 + 1])
				if step1_low < low:
					for l in range(k):
						step2_low = step1_low + dist(b[2 * j], b[j * 2 + 1], c[2 * l], c[l * 2 + 1])
						if step2_low < low:
							low = step2_low
	low_2 = sys.maxsize
	for i in range(m):
		probable_low = dist(x, y, b[2 * i], b[2 * i + 1])
		if probable_low < low_2:
			for j in range(n):
				step1_low = probable_low + dist(b[2 * i], b[2 * i + 1], a[2 * j], a[2 * j + 1])
				if step1_low < low_2:
					for l in range(k):
						step2_low = step1_low + dist(a[2 * j], a[j * 2 + 1], c[2 * l], c[l * 2 + 1])
						if step2_low < low_2:
							low_2 = step2_low
	print(min(low, low_2))


import math
from collections import defaultdict
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().strip().split())
	(N, M, K) = map(int, input().strip().split())
	A = list(map(int, input().strip().split()))
	B = list(map(int, input().strip().split()))
	C = list(map(int, input().strip().split()))
	min_dist_1 = math.inf
	for i in range(0, 2 * N - 1, 2):
		total_dist_1 = math.sqrt((x - A[i]) ** 2 + (y - A[i + 1]) ** 2)
		if total_dist_1 < min_dist_1:
			for j in range(0, 2 * M - 1, 2):
				total_dist_2 = total_dist_1 + math.sqrt((A[i] - B[j]) ** 2 + (A[i + 1] - B[j + 1]) ** 2)
				if total_dist_2 < min_dist_1:
					for k in range(0, 2 * K - 1, 2):
						total_dist_3 = total_dist_2 + math.sqrt((B[j] - C[k]) ** 2 + (B[j + 1] - C[k + 1]) ** 2)
						if total_dist_3 < min_dist_1:
							min_dist_1 = total_dist_3
	min_dist_2 = math.inf
	for j in range(0, 2 * M - 1, 2):
		key_a = -1
		total_dist_1 = math.sqrt((x - B[j]) ** 2 + (y - B[j + 1]) ** 2)
		if total_dist_1 < min_dist_2:
			for i in range(0, 2 * N - 1, 2):
				key_a += 1
				total_dist_2 = total_dist_1 + math.sqrt((A[i] - B[j]) ** 2 + (A[i + 1] - B[j + 1]) ** 2)
				if total_dist_2 < min_dist_2:
					for k in range(0, 2 * K - 1, 2):
						total_dist_3 = total_dist_2 + math.sqrt((A[i] - C[k]) ** 2 + (A[i + 1] - C[k + 1]) ** 2)
						if total_dist_3 < min_dist_2:
							min_dist_2 = total_dist_3
	print(round(min(min_dist_1, min_dist_2), 10))


import math

def distance(a, b, l1, l2):
	return math.sqrt((a - l1) ** 2 + (b - l2) ** 2)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	nn = list(map(int, input().split()))
	mm = list(map(int, input().split()))
	kk = list(map(int, input().split()))
	p1 = 99999999999999999
	for i in range(0, n * 2, 2):
		z1 = distance(x, y, nn[i], nn[i + 1])
		if z1 < p1:
			for j in range(0, m * 2, 2):
				z2 = z1 + distance(nn[i], nn[i + 1], mm[j], mm[j + 1])
				if z2 < p1:
					for l in range(0, k * 2, 2):
						z3 = z2 + distance(mm[j], mm[j + 1], kk[l], kk[l + 1])
						if z3 < p1:
							p1 = min(p1, z3)
	for i in range(0, m * 2, 2):
		z4 = distance(x, y, mm[i], mm[i + 1])
		if z4 < p1:
			for j in range(0, n * 2, 2):
				z5 = z4 + distance(mm[i], mm[i + 1], nn[j], nn[j + 1])
				if z5 < p1:
					for l in range(0, k * 2, 2):
						z6 = z5 + distance(nn[j], nn[j + 1], kk[l], kk[l + 1])
						if z6 < p1:
							p1 = min(p1, z6)
	print(round(p1, 10))


import math

def euc_dist(a1, b1, a2, b2):
	return math.sqrt((a2 - a1) ** 2 + (b2 - b1) ** 2)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	path1 = math.inf
	for i in range(0, n * 2, 2):
		p_a = euc_dist(x, y, a[i], a[i + 1])
		if p_a < path1:
			for j in range(0, m * 2, 2):
				p_a_b = p_a + euc_dist(a[i], a[i + 1], b[j], b[j + 1])
				if p_a_b < path1:
					for l in range(0, k * 2, 2):
						p_a_b_c = p_a_b + euc_dist(b[j], b[j + 1], c[l], c[l + 1])
						if p_a_b_c < path1:
							path1 = p_a_b_c
	path2 = math.inf
	for i in range(0, m * 2, 2):
		p_b = euc_dist(x, y, b[i], b[i + 1])
		if p_b < path2:
			for j in range(0, n * 2, 2):
				p_b_a = p_b + euc_dist(b[i], b[i + 1], a[j], a[j + 1])
				if p_b_a < path2:
					for l in range(0, k * 2, 2):
						p_b_a_c = p_b_a + euc_dist(a[j], a[j + 1], c[l], c[l + 1])
						if p_b_a_c < path2:
							path2 = p_b_a_c
	print(min(path1, path2))


def dist(x, y, p, q):
	return ((x - p) ** 2 + (y - q) ** 2) ** 0.5
for _ in range(int(input())):
	xy = list(map(int, input().split()))
	nmk = list(map(int, input().split()))
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	k = list(map(int, input().split()))
	min_d = 99999999999999999
	for i in range(0, nmk[0] * 2, 2):
		d1 = dist(xy[0], xy[1], n[i], n[i + 1])
		if d1 < min_d:
			for j in range(0, nmk[1] * 2, 2):
				d2 = d1 + dist(n[i], n[i + 1], m[j], m[j + 1])
				if d2 < min_d:
					for l in range(0, nmk[2] * 2, 2):
						d3 = d2 + dist(m[j], m[j + 1], k[l], k[l + 1])
						min_d = min(min_d, d3)
	for i in range(0, nmk[1] * 2, 2):
		d1 = dist(xy[0], xy[1], m[i], m[i + 1])
		if d1 < min_d:
			for j in range(0, nmk[0] * 2, 2):
				d2 = d1 + dist(m[i], m[i + 1], n[j], n[j + 1])
				if d2 < min_d:
					for l in range(0, nmk[2] * 2, 2):
						d3 = d2 + dist(n[j], n[j + 1], k[l], k[l + 1])
						min_d = min(min_d, d3)
	print(min_d)


from math import sqrt

def distance(a, b, m, n):
	return sqrt((a - m) ** 2 + (b - n) ** 2)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	N = list(map(int, input().split()))
	M = list(map(int, input().split()))
	K = list(map(int, input().split()))
	min_dis = distance(x, y, N[0], N[1]) + distance(N[0], N[1], M[0], M[1]) + distance(M[0], M[1], K[0], K[1])
	for a in range(0, n * 2, 2):
		curr1 = distance(x, y, N[a], N[a + 1])
		if curr1 > min_dis:
			continue
		else:
			for b in range(0, m * 2, 2):
				curr2 = distance(N[a], N[a + 1], M[b], M[b + 1])
				if curr1 + curr2 > min_dis:
					continue
				else:
					for c in range(0, k * 2, 2):
						curr3 = distance(M[b], M[b + 1], K[c], K[c + 1])
						if min_dis > curr1 + curr2 + curr3:
							min_dis = curr1 + curr2 + curr3
	for a in range(0, m * 2, 2):
		curr1 = distance(x, y, M[a], M[a + 1])
		if curr1 > min_dis:
			continue
		else:
			for b in range(0, n * 2, 2):
				curr2 = distance(M[a], M[a + 1], N[b], N[b + 1])
				if curr1 + curr2 > min_dis:
					continue
				else:
					for c in range(0, k * 2, 2):
						curr3 = distance(N[b], N[b + 1], K[c], K[c + 1])
						if min_dis > curr1 + curr2 + curr3:
							min_dis = curr1 + curr2 + curr3
	print(min_dis)


import sys
import math

def calculateDistance(x1, x2, y1, y2):
	x1 = round(x1, 6)
	x2 = round(x2, 6)
	y1 = round(y1, 6)
	y2 = round(y2, 6)
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def bruteForce():
	tests = int(input())
	for i in range(tests):
		initialPosition = list(map(int, input().split(' ')))
		numberOfPoints = list(map(int, input().split(' ')))
		pointsN = list(map(int, input().split(' ')))
		pointsM = list(map(int, input().split(' ')))
		pointsK = list(map(int, input().split(' ')))
		sumDistanceList = list()
		minSumDistance = sys.maxsize
		for numberN in range(numberOfPoints[0]):
			firstWalk = calculateDistance(initialPosition[0], pointsN[numberN * 2], initialPosition[1], pointsN[numberN * 2 + 1])
			if firstWalk < minSumDistance:
				for numberM in range(numberOfPoints[1]):
					secondWalk = calculateDistance(pointsN[numberN * 2], pointsM[numberM * 2], pointsN[numberN * 2 + 1], pointsM[numberM * 2 + 1])
					initialToSecond = firstWalk + secondWalk
					if initialToSecond < minSumDistance:
						for numberK in range(numberOfPoints[2]):
							thirdWalk = calculateDistance(pointsM[numberM * 2], pointsK[numberK * 2], pointsM[numberM * 2 + 1], pointsK[numberK * 2 + 1])
							initialToThird = initialToSecond + thirdWalk
							if initialToThird < minSumDistance:
								minSumDistance = initialToThird
		for numberM in range(numberOfPoints[1]):
			firstWalk = calculateDistance(initialPosition[0], pointsM[numberM * 2], initialPosition[1], pointsM[numberM * 2 + 1])
			if firstWalk < minSumDistance:
				for numberN in range(numberOfPoints[0]):
					secondWalk = calculateDistance(pointsM[numberM * 2], pointsN[numberN * 2], pointsM[numberM * 2 + 1], pointsN[numberN * 2 + 1])
					initialToSecond = firstWalk + secondWalk
					if initialToSecond < minSumDistance:
						for numberK in range(numberOfPoints[2]):
							thirdWalk = calculateDistance(pointsN[numberN * 2], pointsK[numberK * 2], pointsN[numberN * 2 + 1], pointsK[numberK * 2 + 1])
							initialToThird = initialToSecond + thirdWalk
							if initialToThird < minSumDistance:
								minSumDistance = initialToThird
		print(minSumDistance)
bruteForce()


import math

def takingInput():
	(a, b) = ([], [])
	s = input().split(' ')
	for i in range(0, len(s), 2):
		a.append(int(s[i]))
		b.append(int(s[i + 1]))
	return (a, b)

def findDist(x1, x2, x3, x4):
	a = x3 - x1
	b = x4 - x2
	return math.sqrt(a * a + b * b)
t = int(input())
while t > 0:
	t -= 1
	(x, y) = [int(i) for i in input().split(' ')]
	(N, M, K) = [int(i) for i in input().split(' ')]
	(a, b) = takingInput()
	(c, d) = takingInput()
	(e, f) = takingInput()
	min1 = 10 ** 19 + 1
	for i in range(N):
		dist = findDist(x, y, a[i], b[i])
		if dist < min1:
			for j in range(M):
				dist2 = dist + findDist(a[i], b[i], c[j], d[j])
				if dist2 < min1:
					for k in range(K):
						min1 = min(min1, dist2 + findDist(c[j], d[j], e[k], f[k]))
	for i in range(M):
		dist = findDist(x, y, c[i], d[i])
		if dist < min1:
			for j in range(N):
				dist2 = dist + findDist(c[i], d[i], a[j], b[j])
				if dist2 < min1:
					for k in range(K):
						min1 = min(min1, dist2 + findDist(a[j], b[j], e[k], f[k]))
	print(min1)


from math import sqrt
import heapq

def arr_maker(stg):
	l = list(map(int, input().split()))
	arr = []
	for i in range(0, len(l), 2):
		arr.append([l[i], l[i + 1], stg])
	return arr

def dist_finder(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def dist_calci(ta, tb, tc, x, y, r=0):
	ch = []
	pts = ta + tb + tc
	visited = [0] * len(pts)
	dis = [float('inf')] * len(pts)
	heapq.heapify(ch)
	ans = float('inf')
	for i in range(len(ta)):
		dis[i] = dist_finder(pts[i][0], pts[i][1], x, y)
		heapq.heappush(ch, [dis[i], i, pts[i][-1]])
	while len(ch):
		cur = heapq.heappop(ch)
		if not visited[cur[1]]:
			visited[cur[1]] = 1
		else:
			continue
		if r:
			if cur[-1] == 'a':
				cur[-1] = 'b'
			elif cur[-1] == 'b':
				cur[-1] = 'a'
		if cur[-1] == 'a':
			(s, e) = (len(ta), len(ta) + len(tb))
			(x, y) = (pts[cur[1]][0], pts[cur[1]][1])
		elif cur[-1] == 'b':
			(s, e) = (len(ta) + len(tb), len(ta) + len(tb) + len(tc))
			(x, y) = (pts[cur[1]][0], pts[cur[1]][1])
		elif cur[-1] == 'c':
			ans = min(ans, dis[cur[1]])
			return ans
			break
		for (i, d) in enumerate(pts[s:e], s):
			if not visited[i]:
				dist = dist_finder(d[0], d[1], x, y)
				dis[i] = min(dis[i], dis[cur[1]] + dist)
				heapq.heappush(ch, [dis[i], i, pts[i][-1]])
tc = int(input())
for _ in range(tc):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	ta = arr_maker('a')
	tb = arr_maker('b')
	tc = arr_maker('c')
	a = dist_calci(ta, tb, tc, x, y)
	b = dist_calci(tb, ta, tc, x, y, 1)
	m = min(a, b)
	print('{0:.10f}'.format(m))


import math
import sys

def dist(x1, y1, x2, y2):
	ans = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	return ans
t = int(input())
for ti in range(t):
	ans = 0
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	nl = list(map(int, input().split()))
	ml = list(map(int, input().split()))
	kl = list(map(int, input().split()))
	low = sys.maxsize
	for i in range(0, n * 2 - 1, 2):
		d1 = dist(x, y, nl[i], nl[i + 1])
		if d1 < low:
			for j in range(0, 2 * m - 1, 2):
				d2 = d1 + dist(nl[i], nl[i + 1], ml[j], ml[j + 1])
				if d2 < low:
					for u in range(0, 2 * k - 1, 2):
						d3 = d2 + dist(ml[j], ml[j + 1], kl[u], kl[u + 1])
						if d3 < low:
							low = d3
	lower = sys.maxsize
	for i in range(0, 2 * m - 1, 2):
		d1 = dist(x, y, ml[i], ml[i + 1])
		if d1 < lower:
			for j in range(0, 2 * n - 1, 2):
				d2 = d1 + dist(ml[i], ml[i + 1], nl[j], nl[j + 1])
				if d2 < lower:
					for u in range(0, 2 * k - 1, 2):
						d3 = d2 + dist(nl[j], nl[j + 1], kl[u], kl[u + 1])
						if d3 < lower:
							lower = d3
	print(min(low, lower))


import math

def calculateDistance(x1, y1, x2, y2):
	distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	return distance
for t in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	num = list(map(int, input().split()))
	n1 = []
	n2 = []
	for i in range(len(num)):
		if i % 2 == 0:
			n1.append(num[i])
		else:
			n2.append(num[i])
	num = list(map(int, input().split()))
	m1 = []
	m2 = []
	for i in range(len(num)):
		if i % 2 == 0:
			m1.append(num[i])
		else:
			m2.append(num[i])
	num = list(map(int, input().split()))
	k1 = []
	k2 = []
	for i in range(len(num)):
		if i % 2 == 0:
			k1.append(num[i])
		else:
			k2.append(num[i])
	mina = float('inf')
	for i in range(n):
		dist1 = calculateDistance(n1[i], n2[i], x, y)
		if dist1 < mina:
			for j in range(m):
				dist2 = dist1 + calculateDistance(m1[j], m2[j], n1[i], n2[i])
				if dist2 < mina:
					for l in range(k):
						dist3 = dist2 + calculateDistance(m1[j], m2[j], k1[l], k2[l])
						if dist3 < mina:
							mina = dist3
	minb = float('inf')
	for i in range(m):
		dist1 = calculateDistance(m1[i], m2[i], x, y)
		if dist1 < minb:
			for j in range(n):
				dist2 = dist1 + calculateDistance(n1[j], n2[j], m1[i], m2[i])
				if dist2 < minb:
					for l in range(k):
						dist3 = dist2 + calculateDistance(n1[j], n2[j], k1[l], k2[l])
						if dist3 < minb:
							minb = dist3
	if minb < mina:
		print('{0:.10f}'.format(minb))
	else:
		print('{0:.10f}'.format(mina))


from sys import stdin
import math
t = int(stdin.readline())
while t:
	(x, y) = [int(x) for x in stdin.readline().split()]
	(n, m, k) = [int(x) for x in stdin.readline().split()]
	s1 = [int(x) for x in stdin.readline().split()]
	s2 = [int(x) for x in stdin.readline().split()]
	s3 = [int(x) for x in stdin.readline().split()]
	ans1 = float('inf')
	for i in range(0, 2 * n, 2):
		d1 = math.sqrt((x - s1[i]) ** 2 + (y - s1[i + 1]) ** 2)
		if d1 < ans1:
			for j in range(0, 2 * m, 2):
				d2 = d1 + math.sqrt((s2[j] - s1[i]) ** 2 + (s2[j + 1] - s1[i + 1]) ** 2)
				if d2 < ans1:
					for l in range(0, 2 * k, 2):
						d3 = d2 + math.sqrt((s2[j] - s3[l]) ** 2 + (s2[j + 1] - s3[l + 1]) ** 2)
						if d3 < ans1:
							ans1 = d3
	ans2 = float('inf')
	for i in range(0, 2 * m, 2):
		d1 = math.sqrt((x - s2[i]) ** 2 + (y - s2[i + 1]) ** 2)
		if d1 < ans2:
			for j in range(0, 2 * n, 2):
				d2 = d1 + math.sqrt((s2[i] - s1[j]) ** 2 + (s2[i + 1] - s1[j + 1]) ** 2)
				if d2 < ans2:
					for l in range(0, 2 * k, 2):
						d3 = d2 + math.sqrt((s1[j] - s3[l]) ** 2 + (s1[j + 1] - s3[l + 1]) ** 2)
						if d3 < ans2:
							ans2 = d3
	print(min(ans1, ans2))
	t -= 1


import math

def distance(x, y, x1, y1):
	return math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	low = math.inf
	for i in range(0, len(A), 2):
		d = distance(x, y, A[i], A[i + 1])
		if d < low:
			for j in range(0, len(B), 2):
				d1 = d + distance(A[i], A[i + 1], B[j], B[j + 1])
				if d1 < low:
					for l in range(0, len(C), 2):
						d2 = d1 + distance(B[j], B[j + 1], C[l], C[l + 1])
						if d2 < low:
							low = d2
	lowest = math.inf
	for i in range(0, len(B), 2):
		d = distance(x, y, B[i], B[i + 1])
		if d < lowest:
			for j in range(0, len(A), 2):
				d1 = d + distance(B[i], B[i + 1], A[j], A[j + 1])
				if d1 < lowest:
					for l in range(0, len(C), 2):
						d2 = d1 + distance(A[j], A[j + 1], C[l], C[l + 1])
						if d2 < lowest:
							lowest = d2
	print(min(low, lowest))


try:
	tc = int(input())
except:
	exit()

def dist(a, b, c, d):
	return ((a - c) ** 2 + (b - d) ** 2) ** 0.5
for _ in range(tc):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	ln = list(map(int, input().split()))
	lm = list(map(int, input().split()))
	lk = list(map(int, input().split()))
	mindis = 10000000000
	for i in range(n):
		dis = dist(x, y, ln[2 * i], ln[2 * i + 1])
		if dis < mindis:
			for j in range(m):
				dis2 = dis + dist(ln[2 * i], ln[2 * i + 1], lm[2 * j], lm[2 * j + 1])
				if dis2 < mindis:
					for c in range(k):
						dis3 = dis2 + dist(lm[2 * j], lm[2 * j + 1], lk[2 * c], lk[2 * c + 1])
						if dis3 < mindis:
							mindis = dis3
	for i in range(m):
		dis = dist(x, y, lm[2 * i], lm[2 * i + 1])
		if dis < mindis:
			for j in range(n):
				dis2 = dis + dist(lm[2 * i], lm[2 * i + 1], ln[2 * j], ln[2 * j + 1])
				if dis2 < mindis:
					for c in range(k):
						dis3 = dis2 + dist(ln[2 * j], ln[2 * j + 1], lk[2 * c], lk[2 * c + 1])
						if dis3 < mindis:
							mindis = dis3
	print(mindis)


from math import sqrt
inf = 9e+18
sq = lambda a: a * a
dist = lambda x1, y1, x2, y2: sqrt(sq(x1 - x2) + sq(y1 - y2))
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(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()]
	ans = inf
	for i in range(n):
		ina = i << 1
		(aix, aiy) = (a[ina], a[ina | 1])
		xa = dist(x, y, aix, aiy)
		if xa < ans:
			for j in range(m):
				inb = j << 1
				(bjx, bjy) = (b[inb], b[inb | 1])
				xab = xa + dist(aix, aiy, bjx, bjy)
				if xab < ans:
					for l in range(k):
						inc = l << 1
						(clx, cly) = (c[inc], c[inc | 1])
						xabc = xab + dist(bjx, bjy, clx, cly)
						ans = min(ans, xabc)
	for j in range(m):
		inb = j << 1
		(bjx, bjy) = (b[inb], b[inb | 1])
		xb = dist(x, y, bjx, bjy)
		if xb < ans:
			for i in range(n):
				ina = i << 1
				(aix, aiy) = (a[ina], a[ina | 1])
				xba = xb + dist(bjx, bjy, aix, aiy)
				if xba < ans:
					for l in range(k):
						inc = l << 1
						(clx, cly) = (c[inc], c[inc | 1])
						xbac = xba + dist(aix, aiy, clx, cly)
						ans = min(ans, xbac)
	print(ans)


from math import sqrt

def distance(x1, y1, x2, y2):
	return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
T = int(input())
for _ in range(T):
	S = list(map(int, input().split()))
	G = list(map(int, input().split()))
	N = list(map(int, input().split()))
	M = list(map(int, input().split()))
	K = list(map(int, input().split()))
	m = 10 ** 11
	for i in range(0, len(N), 2):
		d1 = distance(N[i], N[i + 1], S[0], S[1])
		if m < d1:
			continue
		else:
			for j in range(0, len(M), 2):
				d2 = distance(N[i], N[i + 1], M[j], M[j + 1])
				if m < d1 + d2:
					continue
				else:
					for r in range(0, len(K), 2):
						d3 = distance(M[j], M[j + 1], K[r], K[r + 1])
						if d1 + d2 + d3 < m:
							m = d1 + d2 + d3
	n = 10 ** 11
	for i in range(0, len(M), 2):
		d1 = distance(M[i], M[i + 1], S[0], S[1])
		if n < d1:
			continue
		else:
			for j in range(0, len(N), 2):
				d2 = distance(M[i], M[i + 1], N[j], N[j + 1])
				if n < d1 + d2:
					continue
				else:
					for r in range(0, len(K), 2):
						d3 = distance(N[j], N[j + 1], K[r], K[r + 1])
						if d1 + d2 + d3 < n:
							n = d1 + d2 + d3
	print(min(m, n))


from math import sqrt
import sys

def find_dist(x1, y1, x2, y2):
	return sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def test_case():
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	set_n = list(map(int, input().split()))
	set_m = list(map(int, input().split()))
	set_k = list(map(int, input().split()))
	min1 = sys.maxsize
	for i in range(0, 2 * n - 1, 2):
		sn = find_dist(x, y, set_n[i], set_n[i + 1])
		if sn < min1:
			for j in range(0, 2 * m - 1, 2):
				snm = sn + find_dist(set_n[i], set_n[i + 1], set_m[j], set_m[j + 1])
				if snm < min1:
					for e in range(0, 2 * k - 1, 2):
						snme = snm + find_dist(set_m[j], set_m[j + 1], set_k[e], set_k[e + 1])
						if snme < min1:
							min1 = snme
	min2 = sys.maxsize
	for i in range(0, 2 * m - 1, 2):
		sm = find_dist(x, y, set_m[i], set_m[i + 1])
		if sm < min2:
			for j in range(0, 2 * n - 1, 2):
				smn = sm + find_dist(set_m[i], set_m[i + 1], set_n[j], set_n[j + 1])
				if smn < min2:
					for e in range(0, 2 * k - 1, 2):
						smne = smn + find_dist(set_n[j], set_n[j + 1], set_k[e], set_k[e + 1])
						if smne < min2:
							min2 = smne
	print(min(min1, min2))
t = int(input())
for tc in range(t):
	test_case()


from math import sqrt, inf
rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]

def dist(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def sol(n, m, k, x):
	ca = rrm()
	cb = rrm()
	cc = rrm()
	res = inf
	for i in range(n):
		q = dist(x[0], x[1], ca[2 * i], ca[2 * i + 1])
		if q < res:
			for j in range(m):
				w = q + dist(ca[2 * i], ca[2 * i + 1], cb[2 * j], cb[2 * j + 1])
				if w < res:
					for l in range(k):
						e = w + dist(cb[2 * j], cb[2 * j + 1], cc[2 * l], cc[2 * l + 1])
						if e < res:
							res = e
	for i in range(m):
		q = dist(x[0], x[1], cb[2 * i], cb[2 * i + 1])
		if q < res:
			for j in range(n):
				w = q + dist(cb[2 * i], cb[2 * i + 1], ca[2 * j], ca[2 * j + 1])
				if w < res:
					for l in range(k):
						e = w + dist(ca[2 * j], ca[2 * j + 1], cc[2 * l], cc[2 * l + 1])
						if e < res:
							res = e
	return res
T = rri()
for _ in range(T):
	x = rrm()
	(n, m, k) = rrm()
	ans = sol(n, m, k, x)
	print(ans)


import sys
import math

def dis(x1, y1, x2, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(N, M, K) = map(int, input().split())
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	k = list(map(int, input().split()))
	d = sys.maxsize
	for i in range(0, 2 * N, 2):
		a = dis(x, y, n[i], n[i + 1])
		if a < d:
			for j in range(0, 2 * M, 2):
				b = a + dis(n[i], n[i + 1], m[j], m[j + 1])
				if b < d:
					for l in range(0, 2 * K, 2):
						c = b + dis(m[j], m[j + 1], k[l], k[l + 1])
						if c < d:
							d = c
	e = sys.maxsize
	for i in range(0, 2 * M, 2):
		a = dis(x, y, m[i], m[i + 1])
		if a < e:
			for j in range(0, 2 * N, 2):
				b = a + dis(m[i], m[i + 1], n[j], n[j + 1])
				if b < e:
					for l in range(0, 2 * K, 2):
						c = b + dis(n[j], n[j + 1], k[l], k[l + 1])
						if c < e:
							e = c
	print(min(d, e))


import math
import sys

def dist(x, y, a, b):
	d = math.sqrt((x - a) ** 2 + (y - b) ** 2)
	return d
for _ in range(int(input())):
	(x, y) = map(int, input().split(' '))
	(n, m, k) = map(int, input().split(' '))
	li1 = list(map(int, input().split(' ')))
	li2 = list(map(int, input().split(' ')))
	li3 = list(map(int, input().split(' ')))
	mindist = sys.maxsize
	for i in range(0, len(li1) - 1, 2):
		d1 = dist(x, y, li1[i], li1[i + 1])
		if d1 < mindist:
			for j in range(0, len(li2) - 1, 2):
				d2 = dist(li1[i], li1[i + 1], li2[j], li2[j + 1]) + d1
				if d2 < mindist:
					for k in range(0, len(li3) - 1, 2):
						d3 = d2 + dist(li2[j], li2[j + 1], li3[k], li3[k + 1])
						if d3 < mindist:
							mindist = min(mindist, d3)
	mindist2 = sys.maxsize
	for i in range(0, len(li2) - 1, 2):
		d1 = dist(x, y, li2[i], li2[i + 1])
		if d1 < mindist2:
			for j in range(0, len(li1) - 1, 2):
				d2 = dist(li2[i], li2[i + 1], li1[j], li1[j + 1]) + d1
				if d2 < mindist2:
					for k in range(0, len(li3) - 1, 2):
						d3 = dist(li1[j], li1[j + 1], li3[k], li3[k + 1]) + d2
						if d3 < mindist2:
							mindist2 = min(mindist, d3)
	print(min(mindist, mindist2))


import math

def dis(x1, y1, x2, y2):
	return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def ted(f, s, l, x, y):
	mn = 10000000000
	m1 = 10000000000
	m2 = 10000000000
	m3 = 10000000000
	for i in range(0, len(f), 2):
		m1 = dis(x, y, f[i], f[i + 1])
		if m1 > mn:
			continue
		for j in range(0, len(s), 2):
			m2 = m1 + dis(f[i], f[i + 1], s[j], s[j + 1])
			if m2 > mn:
				continue
			for k in range(0, len(l), 2):
				m3 = m2 + dis(s[j], s[j + 1], l[k], l[k + 1])
				if m3 < mn:
					mn = m3
	return mn
t = int(input())
for ts in range(t):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	ln = list(map(int, input().split()))
	lm = list(map(int, input().split()))
	lk = list(map(int, input().split()))
	a = ted(ln, lm, lk, x, y)
	b = ted(lm, ln, lk, x, y)
	print(min(a, b))


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = list(map(int, input().split()))
	e = list(map(int, input().split()))
	mindis = 10000000000
	b = []
	o = []
	p = []
	for i in range(n):
		l = ((x - a[2 * i]) ** 2 + (y - a[2 * i + 1]) ** 2) ** (1 / 2)
		if l < mindis:
			for j in range(m):
				f = l + ((c[2 * j] - a[2 * i]) ** 2 + (c[2 * j + 1] - a[2 * i + 1]) ** 2) ** (1 / 2)
				if f < mindis:
					for d in range(k):
						g = f + ((e[2 * d] - c[2 * j]) ** 2 + (e[2 * d + 1] - c[2 * j + 1]) ** 2) ** (1 / 2)
						if g < mindis:
							mindis = g
	for i in range(m):
		l = ((x - c[2 * i]) ** 2 + (y - c[2 * i + 1]) ** 2) ** (1 / 2)
		if l < mindis:
			for j in range(n):
				f = l + ((c[2 * i] - a[2 * j]) ** 2 + (c[2 * i + 1] - a[2 * j + 1]) ** 2) ** (1 / 2)
				if f < mindis:
					for d in range(k):
						g = f + ((e[2 * d] - a[2 * j]) ** 2 + (e[2 * d + 1] - a[2 * j + 1]) ** 2) ** (1 / 2)
						if g < mindis:
							mindis = g
	print(mindis)


def distance(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
test = int(input())
for i in range(test):
	(x, y) = map(int, input().split())
	string = list(map(int, input().strip().split()))
	n = string[0]
	m = string[1]
	k = string[2]
	lst1 = list(map(int, input().strip().split()))
	lst2 = list(map(int, input().strip().split()))
	lst3 = list(map(int, input().strip().split()))
	minn1 = 1000000000000
	for j in range(0, 2 * n, +2):
		dist = distance(lst1[j], lst1[j + 1], x, y)
		if dist < minn1:
			for ll in range(0, 2 * m, +2):
				adha = dist + distance(lst1[j], lst1[j + 1], lst2[ll], lst2[ll + 1])
				if adha < minn1:
					for kk in range(0, 2 * k, +2):
						pura = adha + distance(lst3[kk], lst3[kk + 1], lst2[ll], lst2[ll + 1])
						if minn1 >= pura:
							minn1 = pura
	minn2 = 1000000000000
	for j in range(0, 2 * m, +2):
		dist = distance(lst2[j], lst2[j + 1], x, y)
		if dist < minn2:
			for ll in range(0, 2 * n, +2):
				adha = dist + distance(lst2[j], lst2[j + 1], lst1[ll], lst1[ll + 1])
				if adha < minn1:
					for kk in range(0, 2 * k, +2):
						pura = adha + distance(lst3[kk], lst3[kk + 1], lst1[ll], lst1[ll + 1])
						if minn2 >= pura:
							minn2 = pura
	if minn2 <= minn1:
		print(minn2)
	else:
		print(minn1)


t = int(input())
import math
import sys

def dis(x1, y1, x2, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
while t:
	t -= 1
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	low = sys.maxsize
	for i in range(0, 2 * n - 1, 2):
		sa = dis(x, y, a[i], a[i + 1])
		if sa < low:
			for j in range(0, 2 * m - 1, 2):
				sab = sa + dis(a[i], a[i + 1], b[j], b[j + 1])
				if sab < low:
					for l in range(0, 2 * k - 1, 2):
						sabc = sab + dis(b[j], b[j + 1], c[l], c[l + 1])
						if sabc < low:
							low = sabc
	mini = sys.maxsize
	for i in range(0, 2 * m - 1, 2):
		sb = dis(x, y, b[i], b[i + 1])
		if sb < mini:
			for j in range(0, 2 * n - 1, 2):
				sba = sb + dis(b[i], b[i + 1], a[j], a[j + 1])
				if sba < mini:
					for l in range(0, 2 * k - 1, 2):
						sbac = sba + dis(a[j], a[j + 1], c[l], c[l + 1])
						if sbac < mini:
							mini = sbac
	print(min(mini, low))


class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def calc_dist(p1, p2):
	return ((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2) ** 0.5

def read_points():
	(x, y) = input().split()
	start = Point(int(x), int(y))
	(n, m, k) = list(map(int, input().split()))
	parts = []
	for (i, lenth) in enumerate((n, m, k)):
		nums = input().split()
		part = []
		for j in range(lenth):
			part.append(Point(int(nums[2 * j]), int(nums[2 * j + 1])))
		parts.append(part)
	return (start, parts)

def calc_total_distance(stages, order, total_dist):
	(a, b, c) = order
	for p1 in stages[a]:
		d1 = calc_dist(start, p1)
		if d1 >= total_dist:
			continue
		for p2 in stages[b]:
			d2 = d1 + calc_dist(p1, p2)
			if d2 >= total_dist:
				continue
			for end in stages[c]:
				d3 = d2 + calc_dist(p2, end)
				if d3 < total_dist:
					total_dist = d3
	return total_dist
try:
	test_num = int(input())
	for _ in range(test_num):
		(start, stages) = read_points()
		total = float('inf')
		for order in [[0, 1, 2], [1, 0, 2]]:
			total = min(total, calc_total_distance(stages, order, total))
		print(total)
except EOFError:
	pass


import math

def calculate_distance(x1, y1, x2, y2):
	distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	return distance
for t in range(int(input())):
	(x, y) = map(int, input().strip().split())
	(n, m, k) = map(int, input().strip().split())
	arrN = list(map(int, input().strip().split()))
	arrM = list(map(int, input().strip().split()))
	arrK = list(map(int, input().strip().split()))
	min_n = 9999999999999999
	min_m = 9999999999999999
	for j in range(1, 2 * n, 2):
		distStartToNJ = calculate_distance(x, y, arrN[j - 1], arrN[j])
		if distStartToNJ > min_n:
			continue
		for a in range(1, 2 * m, 2):
			distNtoM = calculate_distance(arrN[j - 1], arrN[j], arrM[a - 1], arrM[a])
			totaldistSNM = distStartToNJ + distNtoM
			if totaldistSNM > min_n:
				continue
			for b in range(1, 2 * k, 2):
				distMK = totaldistSNM + calculate_distance(arrM[a - 1], arrM[a], arrK[b - 1], arrK[b])
				if distMK < min_n:
					min_n = distMK
	for j in range(1, 2 * m, 2):
		distStartToMJ = calculate_distance(x, y, arrM[j - 1], arrM[j])
		if distStartToMJ > min_m:
			continue
		for a in range(1, 2 * n, 2):
			distMtoN = calculate_distance(arrM[j - 1], arrM[j], arrN[a - 1], arrN[a])
			totaldistSMN = distStartToMJ + distMtoN
			if totaldistSMN > min_m:
				continue
			for b in range(1, 2 * k, 2):
				distNtoK = calculate_distance(arrN[a - 1], arrN[a], arrK[b - 1], arrK[b])
				distNK = totaldistSMN + distNtoK
				if distNK < min_m:
					min_m = distNK
	print(min(min_n, min_m))


import math
import sys
t = int(input())
for _ in range(t):
	input1 = [int(i) for i in input().split()]
	x = input1[0]
	y = input1[1]
	input2 = [int(i) for i in input().split()]
	n = input2[0]
	m = input2[1]
	k = input2[2]
	n_co = [int(i) for i in input().split()]
	m_co = [int(i) for i in input().split()]
	k_co = [int(i) for i in input().split()]
	sp1 = []
	sp2 = []
	low = sys.maxsize
	for i in range(0, 2 * n, 2):
		dist1 = math.sqrt((x - n_co[i]) * (x - n_co[i]) + (y - n_co[i + 1]) * (y - n_co[i + 1]))
		dist = dist1
		if dist < low:
			for j in range(0, 2 * m, 2):
				dist2 = math.sqrt((n_co[i] - m_co[j]) * (n_co[i] - m_co[j]) + (n_co[i + 1] - m_co[j + 1]) * (n_co[i + 1] - m_co[j + 1]))
				if dist1 + dist2 < low:
					for t1 in range(0, 2 * k, 2):
						dist3 = math.sqrt((m_co[j] - k_co[t1]) * (m_co[j] - k_co[t1]) + (m_co[j + 1] - k_co[t1 + 1]) * (m_co[j + 1] - k_co[t1 + 1]))
						if dist1 + dist2 + dist3 < low:
							low = dist1 + dist2 + dist3
	low1 = sys.maxsize
	for i in range(0, 2 * m, 2):
		dist1 = math.sqrt((x - m_co[i]) * (x - m_co[i]) + (y - m_co[i + 1]) * (y - m_co[i + 1]))
		if dist1 < low1:
			for j in range(0, 2 * n, 2):
				dist2 = math.sqrt((m_co[i] - n_co[j]) * (m_co[i] - n_co[j]) + (m_co[i + 1] - n_co[j + 1]) * (m_co[i + 1] - n_co[j + 1]))
				if dist1 + dist2 < low1:
					for t1 in range(0, 2 * k, 2):
						dist3 = math.sqrt((n_co[j] - k_co[t1]) * (n_co[j] - k_co[t1]) + (n_co[j + 1] - k_co[t1 + 1]) * (n_co[j + 1] - k_co[t1 + 1]))
						if dist1 + dist2 + dist3 < low1:
							low1 = dist1 + dist2 + dist3
	print(min(low, low1))


from bisect import bisect_left as ins
import sys

def dist(p1, p2):
	return ((p1[2] - p2[2]) ** 2 + (p1[3] - p2[3]) ** 2) ** 0.5

def litu(n, li, f, p):
	a = [[0, f, 0, 0] for j in range(n)]
	for i in range(2 * n):
		a[i // 2][2 + i % 2] = int(li[i])
		if i % 2 == 1:
			a[i // 2][0] = dist(p, a[i // 2])
	return sorted(a)

def main():
	t = int(sys.stdin.readline().strip())
	for _ in range(t):
		(x, y) = map(int, sys.stdin.readline().strip().split())
		p = (0, -1, x, y)
		(n, m, k) = map(int, sys.stdin.readline().strip().split())
		an = litu(n, sys.stdin.readline().strip().split(), 1, p)
		am = litu(m, sys.stdin.readline().strip().split(), 2, p)
		ak = litu(k, sys.stdin.readline().strip().split(), 0, p)
		anm = sorted(an + am)
		mi = 10 ** 12
		i = 0
		while i < len(anm):
			(mi, anm, ak) = do(anm[i], anm, ak, mi)
			i += 1
		print(mi)

def do(point, anm, ak, mi):
	j = 0
	while j < len(anm):
		i = anm[j]
		if i[1] != point[1]:
			if dist(point, i) + point[0] > mi:
				j += 1
				continue
			k = 0
			while k < len(ak):
				ik = ak[k]
				reached = dist(i, ik) + dist(point, i) + point[0]
				if reached < mi:
					mi = reached
					(anm, ak) = cut(mi, anm, ak)
				k += 1
		j += 1
	return (mi, anm, ak)

def cut(mi, anm, ak):
	x = ins(anm, [mi, 0, 0, 0])
	anm = anm[:x]
	x = ins(ak, [mi, 0, 0, 0])
	ak = ak[:x]
	return (anm, ak)
main()


from bisect import bisect_left as ins
import atexit
from io import StringIO
from sys import stdin, stdout, __stdout__
_I_B = stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = StringIO()
stdout = _O_B

@atexit.register
def write():
	__stdout__.write(_O_B.getvalue())

def dist(p1, p2):
	return ((p1[2] - p2[2]) ** 2 + (p1[3] - p2[3]) ** 2) ** 0.5

def litu(n, li, f, p):
	a = [[0, f, 0, 0] for j in range(n)]
	for i in range(2 * n):
		a[i // 2][2 + i % 2] = int(li[i])
		if i % 2 == 1:
			a[i // 2][0] = dist(p, a[i // 2])
	return sorted(a)

def main():
	t = int(input())
	for _ in range(t):
		(x, y) = map(int, input().split())
		p = (0, -1, x, y)
		(n, m, k) = map(int, input().split())
		an = litu(n, input().split(), 1, p)
		am = litu(m, input().split(), 2, p)
		ak = litu(k, input().split(), 0, p)
		anm = sorted(an + am)
		mi = 10 ** 12
		i = 0
		while i < len(anm):
			(mi, anm, ak) = do(anm[i], anm, ak, mi)
			i += 1
		print(mi)

def do(point, anm, ak, mi):
	j = 0
	while j < len(anm):
		i = anm[j]
		if i[1] != point[1]:
			if dist(point, i) + point[0] > mi:
				j += 1
				continue
			k = 0
			while k < len(ak):
				ik = ak[k]
				reached = dist(i, ik) + dist(point, i) + point[0]
				if reached < mi:
					mi = reached
					(anm, ak) = cut(mi, anm, ak)
				k += 1
		j += 1
	return (mi, anm, ak)

def cut(mi, anm, ak):
	x = ins(anm, [mi, 0, 0, 0])
	anm = anm[:x]
	x = ins(ak, [mi, 0, 0, 0])
	ak = ak[:x]
	return (anm, ak)
main()


import math

def dist(x1, y1, x2, y2):
	return math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2))
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(N, M, K) = map(int, input().split())
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	k = list(map(int, input().split()))
	ans = 10 ** 12
	for i in range(N):
		d1 = dist(x, y, n[2 * i], n[2 * i + 1])
		for j in range(M):
			if d1 > ans:
				break
			d2 = d1 + dist(n[2 * i], n[2 * i + 1], m[2 * j], m[2 * j + 1])
			for u in range(K):
				if d2 > ans:
					break
				d = d2 + dist(m[2 * j], m[2 * j + 1], k[2 * u], k[2 * u + 1])
				if d < ans:
					ans = d
	for i in range(M):
		d1 = dist(x, y, m[2 * i], m[2 * i + 1])
		for j in range(N):
			if d1 > ans:
				break
			d2 = d1 + dist(m[2 * i], m[2 * i + 1], n[2 * j], n[2 * j + 1])
			for u in range(K):
				if d2 > ans:
					break
				d = d2 + dist(n[2 * j], n[2 * j + 1], k[2 * u], k[2 * u + 1])
				if d < ans:
					ans = d
	print(ans)


import math

def distance(x1, y1, x2, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(len1, len2, len3) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = list(map(int, input().split()))
	m1 = 10000000000
	md2 = 10000000000
	c1 = 0
	c2 = 0
	a1 = 0
	a2 = 0
	m2 = 10000000000
	m3 = 10000000000
	md = 10000000000
	for i in range(0, 2 * len1, 2):
		m1 = distance(x, y, l1[i], l1[i + 1])
		if m1 > md:
			continue
		for j in range(0, 2 * len2, 2):
			m2 = m1 + distance(l1[i], l1[i + 1], l2[j], l2[j + 1])
			if m2 > md:
				continue
			for k in range(0, 2 * len3, 2):
				m3 = m2 + distance(l2[j], l2[j + 1], l3[k], l3[k + 1])
				if m3 < md:
					md = m3
	for i in range(0, 2 * len2, 2):
		m1 = distance(x, y, l2[i], l2[i + 1])
		if m1 > md2:
			continue
		for j in range(0, 2 * len1, 2):
			m2 = m1 + distance(l2[i], l2[i + 1], l1[j], l1[j + 1])
			if m2 > md2:
				continue
			for k in range(0, 2 * len3, 2):
				m3 = m2 + distance(l1[j], l1[j + 1], l3[k], l3[k + 1])
				if m3 < md2:
					md2 = m3
	if md < md2:
		print('{0:.10f}'.format(md))
	else:
		print('{0:.10f}'.format(md2))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	N = list(map(int, input().split()))
	M = list(map(int, input().split()))
	K = list(map(int, input().split()))
	min1 = ((x - N[0]) ** 2 + (y - N[1]) ** 2) ** 0.5 + ((M[0] - N[0]) ** 2 + (M[1] - N[1]) ** 2) ** 0.5 + ((K[0] - M[0]) ** 2 + (K[1] - M[1]) ** 2) ** 0.5
	for i in range(0, 2 * n, 2):
		start = ((x - N[i]) ** 2 + (y - N[i + 1]) ** 2) ** 0.5
		if start < min1:
			for j in range(0, 2 * m, 2):
				dist1 = start + ((M[j] - N[i]) ** 2 + (M[j + 1] - N[i + 1]) ** 2) ** 0.5
				if dist1 < min1:
					for a in range(0, 2 * k, 2):
						dist2 = dist1 + ((K[a] - M[j]) ** 2 + (K[a + 1] - M[j + 1]) ** 2) ** 0.5
						if dist2 < min1:
							min1 = dist2
	min2 = ((x - M[0]) ** 2 + (y - M[1]) ** 2) ** 0.5 + ((M[0] - N[0]) ** 2 + (M[1] - N[1]) ** 2) ** 0.5 + ((K[0] - N[0]) ** 2 + (K[1] - N[1]) ** 2) ** 0.5
	for i in range(0, 2 * m, 2):
		start = ((x - M[i]) ** 2 + (y - M[i + 1]) ** 2) ** 0.5
		if start < min2:
			for j in range(0, 2 * n, 2):
				dist1 = start + ((N[j] - M[i]) ** 2 + (N[j + 1] - M[i + 1]) ** 2) ** 0.5
				if dist1 < min2:
					for a in range(0, 2 * k, 2):
						dist2 = dist1 + ((K[a] - N[j]) ** 2 + (K[a + 1] - N[j + 1]) ** 2) ** 0.5
						if dist2 < min2:
							min2 = dist2
	if min1 < min2:
		print(min1)
	else:
		print(min2)


def dist(x1, y1, x2, y2):
	return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
test = int(input())
while test:
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	(f, s, t) = input().split()
	(f, s, t) = (int(f), int(s), int(t))
	l = [int(i) for i in input().split()]
	a = l[::2]
	b = l[1::2]
	l = [int(i) for i in input().split()]
	c = l[::2]
	di = l[1::2]
	l = [int(i) for i in input().split()]
	e = l[::2]
	fi = l[1::2]
	m = 10000000000000000000000
	for i in range(f):
		d = dist(x, y, a[i], b[i])
		if d < m:
			for j in range(s):
				d1 = d + dist(a[i], b[i], c[j], di[j])
				if d1 < m:
					for k in range(t):
						d2 = d1 + dist(c[j], di[j], e[k], fi[k])
						if d2 < m:
							m = d2
	for i in range(s):
		d = dist(x, y, c[i], di[i])
		if d < m:
			for j in range(f):
				d1 = d + dist(c[i], di[i], a[j], b[j])
				if d1 < m:
					for k in range(t):
						d2 = d1 + dist(a[j], b[j], e[k], fi[k])
						if d2 < m:
							m = d2
	print('%.10f' % m)
	test = test - 1


import math

def dist(x, y, p, q):
	return math.sqrt((x - p) ** 2 + (y - q) ** 2)

def dis(a, b, c, x1, y1):
	ans = 100000000000
	for i in a:
		p = dist(i[0], i[1], x1, y1)
		if p > ans:
			continue
		for j in b:
			q = dist(i[0], i[1], j[0], j[1])
			if p + q > ans:
				continue
			for k in c:
				r = dist(k[0], k[1], j[0], j[1])
				ans = min(ans, p + q + r)
	return ans
for i in range(int(input())):
	(x1, y1) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = []
	b = []
	c = []
	x = [int(n) for n in input().split()]
	for i in range(0, n * 2, 2):
		a.append([x[i], x[i + 1]])
	x = [int(n) for n in input().split()]
	for i in range(0, m * 2, 2):
		b.append([x[i], x[i + 1]])
	x = [int(n) for n in input().split()]
	for i in range(0, k * 2, 2):
		c.append([x[i], x[i + 1]])
	print(round(min(dis(a, b, c, x1, y1), dis(b, a, c, x1, y1)), 10))


import math as m
t = int(input())
while t > 0:
	t -= 1
	(x, y) = map(int, input().split(' '))
	(N, M, K) = map(int, input().split(' '))
	c1 = list(map(int, input().split(' ')))
	c2 = list(map(int, input().split(' ')))
	c3 = list(map(int, input().split(' ')))
	p1 = []
	p2 = []
	p3 = []
	for i in range(0, len(c1), 2):
		p1.append(c1[i:i + 2])
	for i in range(0, len(c2), 2):
		p2.append(c2[i:i + 2])
	for i in range(0, len(c3), 2):
		p3.append(c3[i:i + 2])
	d = m.inf
	for i in range(len(p1)):
		d1 = ((x - p1[i][0]) ** 2 + (y - p1[i][1]) ** 2) ** 0.5
		if d1 >= d:
			continue
		for j in range(len(p2)):
			d2 = ((p2[j][0] - p1[i][0]) ** 2 + (p2[j][1] - p1[i][1]) ** 2) ** 0.5
			if d1 + d2 >= d:
				continue
			for k in range(len(p3)):
				d3 = ((p3[k][0] - p2[j][0]) ** 2 + (p3[k][1] - p2[j][1]) ** 2) ** 0.5
				d5 = d1 + d2 + d3
				if d5 < d:
					d = d5
	for i in range(len(p2)):
		d1 = ((x - p2[i][0]) ** 2 + (y - p2[i][1]) ** 2) ** 0.5
		if d1 >= d:
			continue
		for j in range(len(p1)):
			d2 = ((p1[j][0] - p2[i][0]) ** 2 + (p1[j][1] - p2[i][1]) ** 2) ** 0.5
			if d1 + d2 >= d:
				continue
			for k in range(len(p3)):
				d3 = ((p3[k][0] - p1[j][0]) ** 2 + (p3[k][1] - p1[j][1]) ** 2) ** 0.5
				d5 = d1 + d2 + d3
				if d5 < d:
					d = d5
	print('%.10f' % d)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	(x, y, z) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	p = ((a[0] - m) ** 2 + (a[1] - n) ** 2) ** 0.5 + ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5 + ((c[0] - b[0]) ** 2 + (c[1] - b[1]) ** 2) ** 0.5
	t = 0
	for i in range(0, 2 * x, 2):
		t += ((a[i] - m) ** 2 + (a[i + 1] - n) ** 2) ** 0.5
		if t > p:
			t = 0
			continue
		o = t
		for j in range(0, 2 * y, 2):
			o += ((a[i] - b[j]) ** 2 + (a[i + 1] - b[j + 1]) ** 2) ** 0.5
			if o > p:
				o = t
				continue
			d = o
			for k in range(0, 2 * z, 2):
				d += ((c[k] - b[j]) ** 2 + (c[k + 1] - b[j + 1]) ** 2) ** 0.5
				ee = ((c[k] - b[j]) ** 2 + (c[k + 1] - b[j + 1]) ** 2) ** 0.5
				if d < p:
					p = d
				d = o
			o = t
		t = 0
	t = 0
	for i in range(0, 2 * y, 2):
		t += ((b[i] - m) ** 2 + (b[i + 1] - n) ** 2) ** 0.5
		if t > p:
			t = 0
			continue
		o = t
		for j in range(0, 2 * x, 2):
			o += ((a[j] - b[i]) ** 2 + (a[j + 1] - b[i + 1]) ** 2) ** 0.5
			if o > p:
				o = t
				continue
			d = o
			for k in range(0, 2 * z, 2):
				d += ((c[k] - a[j]) ** 2 + (c[k + 1] - a[j + 1]) ** 2) ** 0.5
				if d < p:
					p = d
				d = o
			o = t
		t = 0
	print(p)


import math
for tc in range(int(input())):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	res = 10 ** 10
	for i in range(0, 2 * n, 2):
		r1 = pow(pow(x - a[i], 2) + pow(y - a[i + 1], 2), 1 / 2)
		for j in range(0, 2 * m, 2):
			if r1 > res:
				break
			r2 = pow(pow(a[i] - b[j], 2) + pow(a[i + 1] - b[j + 1], 2), 1 / 2)
			for l in range(0, 2 * k, 2):
				if r1 + r2 > res:
					break
				r3 = pow(pow(b[j] - c[l], 2) + pow(b[j + 1] - c[l + 1], 2), 1 / 2)
				if r1 + r2 + r3 < res:
					res = r1 + r2 + r3
	for i in range(0, 2 * m, 2):
		r1 = pow(pow(x - b[i], 2) + pow(y - b[i + 1], 2), 1 / 2)
		for j in range(0, 2 * n, 2):
			if r1 > res:
				break
			r2 = pow(pow(b[i] - a[j], 2) + pow(b[i + 1] - a[j + 1], 2), 1 / 2)
			for l in range(0, 2 * k, 2):
				if r1 + r2 > res:
					break
				r3 = pow(pow(a[j] - c[l], 2) + pow(a[j + 1] - c[l + 1], 2), 1 / 2)
				if r1 + r2 + r3 < res:
					res = r1 + r2 + r3
	print('{0:.10f}'.format(res))


import math
t = int(input())
for _ in range(t):
	(x, y) = list(map(int, input().split()))
	(n, m, k) = list(map(int, input().split()))
	N = list(map(int, input().split()))
	M = list(map(int, input().split()))
	K = list(map(int, input().split()))
	mi = 999999999999
	s = 0
	for i in range(0, n * 2, 2):
		d1 = math.sqrt((x - N[i]) ** 2 + (y - N[i + 1]) ** 2)
		if d1 >= mi:
			continue
		for j in range(0, m * 2, 2):
			d2 = math.sqrt((N[i] - M[j]) ** 2 + (N[i + 1] - M[j + 1]) ** 2)
			if d1 + d2 >= mi:
				continue
			for z in range(0, k * 2, 2):
				d3 = math.sqrt((M[j] - K[z]) ** 2 + (M[j + 1] - K[z + 1]) ** 2)
				s = d1 + d2 + d3
				if s < mi:
					mi = s
	mi2 = 99999999999
	s = 0
	for i in range(0, m * 2, 2):
		d1 = math.sqrt((x - M[i]) ** 2 + (y - M[i + 1]) ** 2)
		if d1 >= mi2:
			continue
		for j in range(0, n * 2, 2):
			d2 = math.sqrt((M[i] - N[j]) ** 2 + (M[i + 1] - N[j + 1]) ** 2)
			if d1 + d2 >= mi2:
				continue
			for z in range(0, k * 2, 2):
				d3 = math.sqrt((N[j] - K[z]) ** 2 + (N[j + 1] - K[z + 1]) ** 2)
				s = d1 + d2 + d3
				if s < mi2:
					mi2 = s
	ans = min(mi, mi2)
	print(ans)


from math import sqrt

def findd(S, A, B, C):
	(x1, y1) = (S[0], S[1])
	(x2, y2) = (A[0], A[1])
	(x3, y3) = (B[0], B[1])
	(x4, y4) = (C[0], C[1])
	res = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	res += sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2)
	res += sqrt((x4 - x3) ** 2 + (y4 - y3) ** 2)
	return res

def findd1(S, A):
	(x1, y1) = (S[0], S[1])
	(x2, y2) = (A[0], A[1])
	res = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	return res
for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	(m, n, k) = list(map(int, input().split()))
	mina = 34.3 * 10 ** 8
	minb = 34.3 * 10 ** 8
	M = list(map(int, input().split()))
	N = list(map(int, input().split()))
	K = list(map(int, input().split()))
	for p in range(m):
		(a, b) = (M[2 * p], M[2 * p + 1])
		d1 = findd1([x, y], [a, b])
		if d1 > mina:
			continue
		else:
			for q in range(n):
				(c, d) = (N[2 * q], N[2 * q + 1])
				d2 = findd1([a, b], [c, d])
				if d1 + d2 > mina:
					continue
				else:
					for r in range(k):
						(e, f) = (K[2 * r], K[2 * r + 1])
						D1 = findd([x, y], [a, b], [c, d], [e, f])
						D2 = findd([x, y], [c, d], [a, b], [e, f])
						if min(D1, D2) < mina:
							mina = min(D1, D2)
	for p in range(n):
		(a, b) = (N[2 * p], N[2 * p + 1])
		d1 = findd1([x, y], [a, b])
		if d1 > minb:
			continue
		else:
			for q in range(m):
				(c, d) = (M[2 * q], M[2 * q + 1])
				d2 = findd1([a, b], [c, d])
				if d1 + d2 > minb:
					continue
				else:
					for r in range(k):
						(e, f) = (K[2 * r], K[2 * r + 1])
						D1 = findd([x, y], [a, b], [c, d], [e, f])
						D2 = findd([x, y], [c, d], [a, b], [e, f])
						if min(D1, D2) < minb:
							minb = min(D1, D2)
	print(min(mina, minb))


def pClosest(points, K, x, y):
	points.sort(key=lambda K: (K[0] - x) ** 2 + (K[1] - y) ** 2)
	return points[:K]

def dis(x, y, x1, y1):
	c = pow(x - x1, 2)
	c += pow(y - y1, 2)
	c = pow(c, 0.5)
	return c
t = int(input())
while t:
	t -= 1
	(sx, sy) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	(nc1, mc1, kc1) = ([], [], [])
	nc = list(map(int, input().split()))
	for i in range(0, n, 2):
		nc1.append([nc[i], nc[i + 1]])
	mc = list(map(int, input().split()))
	for i in range(0, m, 2):
		mc1.append([mc[i], mc[i + 1]])
	kc = list(map(int, input().split()))
	for i in range(0, k, 2):
		kc1.append([kc[i], kc[i + 1]])
	f = pClosest(nc1, 1, sx, sy)
	f1 = pClosest(mc1, 1, sx, sy)
	f2 = pClosest(kc1, 1, f1[0][0], f1[0][1])
	d = dis(sx, sy, f[0][0], f[0][1])
	d += dis(f[0][0], f[0][1], f1[0][0], f1[0][1])
	d += dis(f1[0][0], f1[0][1], f2[0][0], f2[0][1])
	for i in range(0, n * 2, 2):
		a = dis(sx, sy, nc[i], nc[i + 1])
		if a > d:
			continue
		for j in range(0, m * 2, 2):
			b = dis(sx, sy, mc[j], mc[j + 1])
			x = dis(nc[i], nc[i + 1], mc[j], mc[j + 1])
			if b > d or x > d or (a + x > d and b + x > d):
				continue
			for z in range(0, k * 2, 2):
				y = dis(kc[z], kc[z + 1], mc[j], mc[j + 1])
				h = dis(kc[z], kc[z + 1], nc[i], nc[i + 1])
				d = min(d, a + x + y, b + x + h)
	print(d)


import math

def st(z, y):
	return math.sqrt((z[0] - y[0]) ** 2 + (z[1] - y[1]) ** 2)
try:
	t = int(input())
	for _ in range(t):
		(x, y) = map(int, input().split())
		(n, m, k) = map(int, input().split())
		n1 = list(map(int, input().split()))
		m1 = list(map(int, input().split()))
		k1 = list(map(int, input().split()))
		(n2, m2, k2) = ([], [], [])
		for i in range(0, 2 * n, 2):
			n2.append([n1[i], n1[i + 1]])
		for i in range(0, 2 * m, 2):
			m2.append([m1[i], m1[i + 1]])
		for i in range(0, 2 * k, 2):
			k2.append([k1[i], k1[i + 1]])
		m = 10 ** 20
		for i in n2:
			a1 = st(i, [x, y])
			if a1 > m:
				continue
			for j in m2:
				a2 = st(i, j)
				a12 = a1 + a2
				if a12 > m:
					continue
				for l in k2:
					a3 = st(l, j)
					a = a1 + a2 + a3
					if i == n2[0] and j == m2[0] and (l == k2[0]):
						m = a
					if m < a:
						continue
					elif m > a:
						m = a
		for i in m2:
			a1 = st(i, [x, y])
			if a1 > m:
				continue
			for j in n2:
				a2 = st(i, j)
				a21 = a1 + a2
				if a21 > m:
					continue
				for l in k2:
					a3 = st(l, j)
					a = a1 + a2 + a3
					if a > m:
						continue
					elif m > a:
						m = a
		print(m)
except:
	pass


import math
import sys

def calc(x1, y1, x2, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
for i in range(int(input())):
	(x, y) = map(int, input().split())
	li0 = [x, y]
	(n, m, k) = map(int, input().split())
	N = list()
	M = list()
	K = list()
	Nn = [int(x) for x in input().split()]
	Mm = [int(x) for x in input().split()]
	Kk = [int(x) for x in input().split()]
	Nd = {}
	Md = {}
	Kd = {}
	for i in range(0, len(Nn), 2):
		N.append([Nn[i], Nn[i + 1]])
		Nd[Nn[i], Nn[i + 1]] = calc(x, y, Nn[i], Nn[i + 1])
	for i in range(0, len(Mm), 2):
		M.append([Mm[i], Mm[i + 1]])
		Md[Mm[i], Mm[i + 1]] = calc(x, y, Mm[i], Mm[i + 1])
	for i in range(0, len(Kk), 2):
		K.append([Kk[i], Kk[i + 1]])
		Kd[Kk[i], Kk[i + 1]] = calc(x, y, Kk[i], Kk[i + 1])
	mini = sys.maxsize
	for i in range(n):
		li1 = tuple(N[i])
		if Nd[li1] >= mini:
			continue
		for j in range(m):
			li2 = tuple(M[j])
			f = calc(li1[0], li1[1], li2[0], li2[1])
			if Nd[li1] + f >= mini:
				continue
			for p in range(k):
				li3 = K[p]
				mini = min(mini, Nd[li1] + f + calc(li2[0], li2[1], li3[0], li3[1]))
	for i in range(m):
		li1 = tuple(M[i])
		if Md[li1] >= mini:
			continue
		for j in range(n):
			li2 = tuple(N[j])
			f = calc(li1[0], li1[1], li2[0], li2[1])
			if Md[li1] + f >= mini:
				continue
			for p in range(k):
				li3 = K[p]
				mini = min(mini, Md[li1] + f + calc(li2[0], li2[1], li3[0], li3[1]))
	print('{0:.10f}'.format(mini))


from math import *
T = int(input())
for t in range(T):
	[x, y] = list((int(i) for i in input().split()))
	[N, M, K] = list((int(i) for i in input().split()))
	pN = []
	pM = []
	pK = []
	l = list((int(i) for i in input().split()))
	for n in range(0, 2 * N, 2):
		pN.append((l[n], l[n + 1]))
	l = list((int(i) for i in input().split()))
	for n in range(0, 2 * M, 2):
		pM.append((l[n], l[n + 1]))
	l = list((int(i) for i in input().split()))
	for n in range(0, 2 * K, 2):
		pK.append((l[n], l[n + 1]))
	d = 99999999999999999
	for n in pN:
		dn = sqrt((x - n[0]) ** 2 + (y - n[1]) ** 2)
		if dn > d:
			continue
		for m in pM:
			dm = sqrt((m[0] - n[0]) ** 2 + (m[1] - n[1]) ** 2)
			if dm + dn > d:
				continue
			for k in pK:
				dk = sqrt((m[0] - k[0]) ** 2 + (m[1] - k[1]) ** 2)
				d = min(d, dn + dm + dk)
	for m in pM:
		dm = sqrt((x - m[0]) ** 2 + (y - m[1]) ** 2)
		if dm > d:
			continue
		for n in pN:
			dn = sqrt((m[0] - n[0]) ** 2 + (m[1] - n[1]) ** 2)
			if dm + dn > d:
				continue
			for k in pK:
				dk = sqrt((n[0] - k[0]) ** 2 + (n[1] - k[1]) ** 2)
				d = min(d, dn + dm + dk)
	print(d)


import math
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split(' '))
	(n, m, g) = map(int, input().split(' '))
	red = [int(red) for red in input().split(' ')]
	blue = [int(blue) for blue in input().split(' ')]
	green = [int(green) for green in input().split(' ')]
	minimum = 10000000000
	total = 0
	for choice in range(2):
		if choice == 0:
			for i in range(0, 2 * n, 2):
				d1 = math.sqrt(math.pow(x - red[i], 2) + math.pow(y - red[i + 1], 2))
				total += d1
				cxpos = red[i]
				cypos = red[i + 1]
				if total < minimum:
					for j in range(0, 2 * m, 2):
						d2 = math.sqrt(math.pow(blue[j] - cxpos, 2) + math.pow(blue[j + 1] - cypos, 2))
						total += d2
						sxpos = blue[j]
						sypos = blue[j + 1]
						if total < minimum:
							for k in range(0, 2 * g, 2):
								d3 = math.sqrt(math.pow(green[k] - sxpos, 2) + math.pow(green[k + 1] - sypos, 2))
								total += d3
								txpos = green[k]
								typos = green[k + 1]
								if total < minimum:
									minimum = total
								total -= d3
						total -= d2
				total = 0
		elif choice == 1:
			for j in range(0, 2 * m, 2):
				d2 = math.sqrt(math.pow(blue[j] - x, 2) + math.pow(blue[j + 1] - y, 2))
				total += d2
				cxpos = blue[j]
				cypos = blue[j + 1]
				if total < minimum:
					for i in range(0, 2 * n, 2):
						d1 = math.sqrt(math.pow(cxpos - red[i], 2) + math.pow(cypos - red[i + 1], 2))
						total += d1
						sxpos = red[i]
						sypos = red[i + 1]
						if total < minimum:
							for k in range(0, 2 * g, 2):
								d3 = math.sqrt(math.pow(green[k] - sxpos, 2) + math.pow(green[k + 1] - sypos, 2))
								total += d3
								txpos = green[k]
								typos = green[k + 1]
								if total < minimum:
									minimum = total
								total -= d3
						total -= d1
				total = 0
	print(minimum)


def distance(a, b):
	return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5
for _ in range(int(input())):
	xy = tuple(list(map(int, input().split())))
	(n, m, k) = list(map(int, input().split()))
	axy = list(map(int, input().split()))
	axy = [(axy[i], axy[i + 1]) for i in range(0, len(axy), 2)]
	bxy = list(map(int, input().split()))
	bxy = [(bxy[i], bxy[i + 1]) for i in range(0, len(bxy), 2)]
	cxy = list(map(int, input().split()))
	cxy = [(cxy[i], cxy[i + 1]) for i in range(0, len(cxy), 2)]
	dif = 1e+50
	for a in axy:
		cur1 = distance(xy, a)
		if cur1 > dif:
			continue
		for b in bxy:
			cur2 = distance(a, b)
			if cur1 + cur2 > dif:
				continue
			for c in cxy:
				x = cur1 + cur2 + distance(b, c)
				dif = min(x, dif)
	dif2 = 1e+50
	for b in bxy:
		cur1 = distance(xy, b)
		if cur1 > dif2:
			continue
		for a in axy:
			cur2 = distance(b, a)
			if cur1 + cur2 > dif2:
				continue
			for c in cxy:
				x = cur1 + cur2 + distance(a, c)
				dif2 = min(dif2, x)
	print(min(dif, dif2))


import math
EuclidianDistance = lambda x1, y1, x2, y2: math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))

def main():
	t = int(input())
	for _ in range(t):
		(x, y) = map(int, input().split())
		(n, m, k) = map(int, input().split())
		n_l = list(map(int, input().split()))
		m_l = list(map(int, input().split()))
		k_l = list(map(int, input().split()))
		n_x = []
		n_y = []
		m_x = []
		m_y = []
		k_x = []
		k_y = []
		for i in range(2 * n):
			if i % 2 == 0:
				n_x.append(n_l[i])
			else:
				n_y.append(n_l[i])
		for i in range(2 * m):
			if i % 2 == 0:
				m_x.append(m_l[i])
			else:
				m_y.append(m_l[i])
		for i in range(2 * k):
			if i % 2 == 0:
				k_x.append(k_l[i])
			else:
				k_y.append(k_l[i])
		final = EuclidianDistance(x, y, n_x[0], n_y[0]) + EuclidianDistance(n_x[0], n_y[0], m_x[0], m_y[0]) + EuclidianDistance(m_x[0], m_y[0], k_x[0], k_y[0])
		for i in range(n):
			if EuclidianDistance(x, y, n_x[i], n_y[i]) < final:
				for j in range(m):
					if EuclidianDistance(x, y, n_x[i], n_y[i]) + EuclidianDistance(n_x[i], n_y[i], m_x[j], m_y[j]) < final:
						for h in range(k):
							if EuclidianDistance(x, y, n_x[i], n_y[i]) + EuclidianDistance(n_x[i], n_y[i], m_x[j], m_y[j]) + EuclidianDistance(m_x[j], m_y[j], k_x[h], k_y[h]) < final:
								final = EuclidianDistance(x, y, n_x[i], n_y[i]) + EuclidianDistance(n_x[i], n_y[i], m_x[j], m_y[j]) + EuclidianDistance(m_x[j], m_y[j], k_x[h], k_y[h])
		for i in range(m):
			if EuclidianDistance(x, y, m_x[i], m_y[i]) < final:
				for j in range(n):
					if EuclidianDistance(x, y, m_x[i], m_y[i]) + EuclidianDistance(m_x[i], m_y[i], n_x[j], n_y[j]) < final:
						for h in range(k):
							if EuclidianDistance(x, y, m_x[i], m_y[i]) + EuclidianDistance(m_x[i], m_y[i], n_x[j], n_y[j]) + EuclidianDistance(n_x[j], n_y[j], k_x[h], k_y[h]) < final:
								final = EuclidianDistance(x, y, m_x[i], m_y[i]) + EuclidianDistance(m_x[i], m_y[i], n_x[j], n_y[j]) + EuclidianDistance(n_x[j], n_y[j], k_x[h], k_y[h])
		print(final)
main()


import numpy as np
from numpy.linalg import norm
for _ in range(int(input())):
	p1 = np.array(list(map(int, input().split())))
	(n, m, k) = map(int, input().split())
	ps1 = list(map(int, input().split()))
	ps2 = list(map(int, input().split()))
	ps3 = list(map(int, input().split()))
	(mps1, mps2, mps3) = ([], [], [])
	thing = iter(ps1)
	for val in thing:
		mps1.append(np.array((val, next(thing))))
	thing = iter(ps2)
	for val in thing:
		mps2.append(np.array((val, next(thing))))
	thing = iter(ps3)
	for val in thing:
		mps3.append(np.array((val, next(thing))))
	min_dist = norm(p1 - mps1[0]) + norm(mps1[0] - mps2[0]) + norm(mps2[0] - mps3[0])
	for j in mps1:
		d0 = norm(p1 - j)
		if d0 < min_dist:
			for k in mps2:
				d1 = norm(j - k)
				if d0 + d1 < min_dist:
					for l in mps3:
						d2 = norm(k - l)
						if d0 + d1 + d2 < min_dist:
							min_dist = d0 + d1 + d2
	for j in mps2:
		d0 = norm(p1 - j)
		if d0 < min_dist:
			for k in mps1:
				d1 = norm(j - k)
				if d0 + d1 < min_dist:
					for l in mps3:
						d2 = norm(k - l)
						if d0 + d1 + d2 < min_dist:
							min_dist = d0 + d1 + d2
	print(min_dist)


import math
import sys
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	l1 = []
	l2 = []
	l3 = []
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = list(map(int, input().split()))
	r = sys.maxsize
	for i in range(0, 2 * n - 1, 2):
		r1 = math.sqrt(pow(x - l1[i], 2) + pow(y - l1[i + 1], 2))
		x1 = l1[i]
		y1 = l1[i + 1]
		if r1 < r:
			for j in range(0, 2 * m - 1, 2):
				r2 = r1 + math.sqrt(pow(x1 - l2[j], 2) + pow(y1 - l2[j + 1], 2))
				x2 = l2[j]
				y2 = l2[j + 1]
				if r2 < r:
					for _ in range(0, 2 * k - 1, 2):
						r3 = r2 + math.sqrt(pow(x2 - l3[_], 2) + pow(y2 - l3[_ + 1], 2))
						r = min(r, r3)
	res = sys.maxsize
	for i in range(0, 2 * m - 1, 2):
		r1 = math.sqrt(pow(x - l2[i], 2) + pow(y - l2[i + 1], 2))
		x2 = l2[i]
		y2 = l2[i + 1]
		if r1 < r:
			for j in range(0, 2 * n - 1, 2):
				r2 = r1 + math.sqrt(pow(x2 - l1[j], 2) + pow(y2 - l1[j + 1], 2))
				x1 = l1[j]
				y1 = l1[j + 1]
				if r2 < r:
					for _ in range(0, 2 * k - 1, 2):
						r3 = r2 + math.sqrt(pow(x1 - l3[_], 2) + pow(y1 - l3[_ + 1], 2))
						res = min(res, r3)
	print(min(r, res))


import math

def dis(a, b, c, d):
	k = math.sqrt((a - c) ** 2 + (b - d) ** 2)
	return round(k, 10)
z = int(input())
for i in range(z):
	(x, y) = map(int, input().split())
	(N, M, K) = map(int, input().split())
	a = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	e = [int(x) for x in input().split()]
	t = 10 ** 11
	for i in range(0, len(a), 2):
		d = dis(x, y, a[i], a[i + 1])
		if d >= t:
			continue
		for j in range(0, len(c), 2):
			f = dis(a[i], a[i + 1], c[j], c[j + 1])
			if d + f >= t:
				continue
			for k in range(0, len(e), 2):
				g = dis(c[j], c[j + 1], e[k], e[k + 1])
				if d + f + g >= t:
					continue
				ff = d + f + g
				t = min(t, ff)
	q = 10 ** 11
	for i in range(0, len(c), 2):
		h = dis(x, y, c[i], c[i + 1])
		if h >= q:
			continue
		for j in range(0, len(a), 2):
			l = dis(c[i], c[i + 1], a[j], a[j + 1])
			if h + l >= q:
				continue
			for k in range(0, len(e), 2):
				m = dis(a[j], a[j + 1], e[k], e[k + 1])
				if h + l + m >= q:
					continue
				fff = h + l + m
				q = min(q, fff)
	print(min(t, q))


import math
t = int(input())
while t:
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	alpha = 10000000000000000000000000000000000000000000
	alpha1 = 1000000000000000000000000000000000000000000
	beta = 10000000000000000000000000000000000
	beta1 = 10000000000000000000000000000000000
	zeta = 10000000000000000000000000000000000
	zeta1 = 10000000000000000000000000000000000
	for i in range(0, 2 * n, 2):
		x1 = a[i]
		y1 = a[i + 1]
		sqn = math.sqrt(abs(x1 - x) ** 2 + abs(y1 - y) ** 2)
		if sqn < alpha:
			f_x1 = a[i]
			f_y1 = a[i + 1]
			for j in range(0, 2 * m, 2):
				x2 = b[j]
				y2 = b[j + 1]
				sqm = math.sqrt(abs(f_x1 - x2) ** 2 + abs(f_y1 - y2) ** 2)
				if sqm + sqn < alpha:
					m_x = b[j]
					m_y = b[j + 1]
					for z in range(0, 2 * k, 2):
						x3 = c[z]
						y3 = c[z + 1]
						sqk = math.sqrt(abs(x3 - m_x) ** 2 + abs(y3 - m_y) ** 2)
						if sqk + sqm + sqn < alpha:
							alpha = sqk + sqm + sqn
	for i in range(0, 2 * m, 2):
		x11 = b[i]
		y11 = b[i + 1]
		sqn1 = math.sqrt(abs(x11 - x) ** 2 + abs(y11 - y) ** 2)
		if sqn1 < alpha1:
			f_x11 = b[i]
			f_y11 = b[i + 1]
			for j in range(0, 2 * n, 2):
				x22 = a[j]
				y22 = a[j + 1]
				sqm1 = math.sqrt(abs(f_x11 - x22) ** 2 + abs(f_y11 - y22) ** 2)
				if sqm1 + sqn1 < alpha1:
					m_x1 = a[j]
					m_y1 = a[j + 1]
					for z in range(0, 2 * k, 2):
						x33 = c[z]
						y33 = c[z + 1]
						sqk1 = math.sqrt(abs(x33 - m_x1) ** 2 + abs(y33 - m_y1) ** 2)
						if sqk1 + sqm1 + sqn1 < alpha1:
							alpha1 = sqk1 + sqm1 + sqn1
	res1 = alpha
	res2 = alpha1
	if res1 < res2:
		print('%.10f' % res1)
	else:
		print('%.10f' % res2)
	t -= 1


import math

def pair(set=[]):
	return [(set[i], set[i + 1]) for i in range(0, len(set) - 1, 2)]

def power(a, b):
	res = 1
	while b > 0:
		if b % 2:
			res = res * a
		b = b >> 1
		a = a * a
	return res

def distance(p=(), q=()):
	x = abs(q[0] - p[0])
	y = abs(q[1] - p[1])
	x = power(x, 2)
	y = power(y, 2)
	r = math.sqrt(x + y)
	return r
for _ in range(int(input())):
	(x, y) = [int(i) for i in input().split()]
	(n, m, k) = [int(i) for i in input().split()]
	set1 = [int(i) for i in input().split()]
	set2 = [int(i) for i in input().split()]
	set3 = [int(i) for i in input().split()]
	set1 = pair(set1)
	set2 = pair(set2)
	set3 = pair(set3)
	min1 = float('inf')
	for i in set1:
		distA = distance((x, y), (i[0], i[1]))
		if distA > min1:
			continue
		for j in set2:
			distAB = distance((i[0], i[1]), (j[0], j[1]))
			if distA + distAB > min1:
				continue
			for k in set3:
				distBC = distance((j[0], j[1]), (k[0], k[1]))
				final_dist = distA + distAB + distBC
				if final_dist < min1:
					min1 = final_dist
	for i in set2:
		distB = distance((x, y), (i[0], i[1]))
		if distB > min1:
			continue
		for j in set1:
			distBA = distance((i[0], i[1]), (j[0], j[1]))
			if distB + distBA > min1:
				continue
			for k in set3:
				distAC = distance((j[0], j[1]), (k[0], k[1]))
				final_dist = distB + distBA + distAC
				if final_dist < min1:
					min1 = final_dist
	print(round(min1, 10))


try:
	import math
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		(n, m, k) = map(int, input().split())
		N = list(map(int, input().split()))
		M = list(map(int, input().split()))
		K = list(map(int, input().split()))
		ans = float('inf')
		for (i, j) in zip(N[0::2], N[1::2]):
			dist = math.sqrt((a - i) ** 2 + (b - j) ** 2)
			if dist > ans:
				continue
			for (x, y) in zip(M[0::2], M[1::2]):
				dist1 = dist + math.sqrt((i - x) ** 2 + (j - y) ** 2)
				if dist1 > ans:
					continue
				for (e, f) in zip(K[0::2], K[1::2]):
					dist2 = dist1 + math.sqrt((x - e) ** 2 + (y - f) ** 2)
					if dist2 > ans:
						continue
					ans = dist2
		ans1 = float('inf')
		dist = dist1 = dist2 = 0
		for (i, j) in zip(M[0::2], M[1::2]):
			dist = math.sqrt((a - i) ** 2 + (b - j) ** 2)
			if dist > ans1:
				continue
			for (x, y) in zip(N[0::2], N[1::2]):
				dist1 = dist + math.sqrt((i - x) ** 2 + (j - y) ** 2)
				if dist1 > ans1:
					continue
				for (e, f) in zip(K[0::2], K[1::2]):
					dist2 = dist1 + math.sqrt((x - e) ** 2 + (y - f) ** 2)
					if dist2 > ans1:
						continue
					ans1 = dist2
		if ans < ans1:
			print(ans)
		else:
			print(ans1)
except:
	pass


import sys
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	nmk = input().split()
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	N = list(map(int, input().split()))
	M = list(map(int, input().split()))
	K = list(map(int, input().split()))
	mini = sys.maxsize
	for i in range(0, 2 * m, 2):
		x1 = M[i]
		y1 = M[i + 1]
		d1 = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
		if d1 > mini:
			continue
		for j in range(0, 2 * n, 2):
			x2 = N[j]
			y2 = N[j + 1]
			d2 = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
			if d1 + d2 > mini:
				continue
			for p in range(0, 2 * k, 2):
				x3 = K[p]
				y3 = K[p + 1]
				d3 = ((x3 - x2) ** 2 + (y2 - y3) ** 2) ** 0.5
				d = d1 + d2 + d3
				if d < mini:
					mini = d
	mi = sys.maxsize
	for i in range(0, 2 * n, 2):
		x1 = N[i]
		y1 = N[i + 1]
		d1 = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
		if d1 > mi:
			continue
		for j in range(0, 2 * m, 2):
			x2 = M[j]
			y2 = M[j + 1]
			d2 = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
			if d1 + d2 > mi:
				continue
			for p in range(0, 2 * k, 2):
				x3 = K[p]
				y3 = K[p + 1]
				d3 = ((x3 - x2) ** 2 + (y2 - y3) ** 2) ** 0.5
				dd = d1 + d2 + d3
				if dd < mi:
					mi = dd
	if mini < mi:
		print(mini)
	else:
		print(mi)


def main():
	for _ in range(int(input())):
		(x, y) = map(int, input().split())
		(n, m, k) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = list(map(int, input().split()))
		a = [a[i:i + 2] for i in range(0, len(a), 2)]
		b = [b[i:i + 2] for i in range(0, len(b), 2)]
		c = [c[i:i + 2] for i in range(0, len(c), 2)]
		min = 10 ** 12
		for q in a:
			d1 = ((q[0] - x) ** 2 + (q[1] - y) ** 2) ** 0.5
			if d1 > min:
				continue
			for r in b:
				d2 = ((r[0] - q[0]) ** 2 + (r[1] - q[1]) ** 2) ** 0.5
				if d1 + d2 > min:
					continue
				for s in c:
					d3 = ((s[0] - r[0]) ** 2 + (s[1] - r[1]) ** 2) ** 0.5
					sum = d1 + d2 + d3
					if sum < min:
						min = sum
		for r in b:
			d2 = ((r[0] - x) ** 2 + (r[1] - y) ** 2) ** 0.5
			if d2 > min:
				continue
			for q in a:
				d1 = ((q[0] - r[0]) ** 2 + (q[1] - r[1]) ** 2) ** 0.5
				if d1 + d2 > min:
					continue
				for s in c:
					d3 = ((s[0] - q[0]) ** 2 + (s[1] - q[1]) ** 2) ** 0.5
					sum = d1 + d2 + d3
					if sum < min:
						min = sum
		print(min)
main()


def distance(x, y, a, b):
	dist = (x - a) ** 2 + (y - b) ** 2
	return dist ** 0.5
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	ng = list(map(int, input().split()))
	mg = list(map(int, input().split()))
	kg = list(map(int, input().split()))
	ng = [[ng[i], ng[i + 1]] for i in range(0, 2 * n, 2)]
	mg = [[mg[i], mg[i + 1]] for i in range(0, 2 * m, 2)]
	kg = [[kg[i], kg[i + 1]] for i in range(0, 2 * k, 2)]
	req = distance(x, y, ng[0][0], ng[0][1]) + distance(ng[0][0], ng[0][1], mg[0][0], mg[0][1]) + distance(kg[0][0], kg[0][1], mg[0][0], mg[0][1])
	for i in range(n):
		d1 = distance(x, y, ng[i][0], ng[i][1])
		if d1 >= req:
			continue
		for j in range(m):
			d2 = d1 + distance(ng[i][0], ng[i][1], mg[j][0], mg[j][1])
			if d2 >= req:
				continue
			for r in range(k):
				d = d2 + distance(kg[r][0], kg[r][1], mg[j][0], mg[j][1])
				req = min(req, d)
	for j in range(m):
		d1 = distance(x, y, mg[j][0], mg[j][1])
		if d1 >= req:
			continue
		for i in range(n):
			d2 = d1 + distance(ng[i][0], ng[i][1], mg[j][0], mg[j][1])
			if d2 >= req:
				continue
			for r in range(k):
				d = d2 + distance(kg[r][0], kg[r][1], ng[i][0], ng[i][1])
				req = min(req, d)
	print(req)


T = int(input())
for t in range(T):
	min = 1000000000000
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	nl = list(map(int, input().split()))
	ml = list(map(int, input().split()))
	kl = list(map(int, input().split()))
	for i in range(0, 2 * n, 2):
		a1 = ((nl[i] - x) ** 2 + (nl[i + 1] - y) ** 2) ** 0.5
		if a1 >= min:
			continue
		for j in range(0, 2 * m, 2):
			a2 = ((nl[i] - ml[j]) ** 2 + (nl[i + 1] - ml[j + 1]) ** 2) ** 0.5
			if a1 + a2 >= min:
				continue
			for h in range(0, 2 * k, 2):
				dist = a1 + a2 + ((ml[j] - kl[h]) ** 2 + (ml[j + 1] - kl[h + 1]) ** 2) ** 0.5
				if dist < min:
					min = dist
	for i in range(0, 2 * m, 2):
		a1 = ((ml[i] - x) ** 2 + (ml[i + 1] - y) ** 2) ** 0.5
		if a1 >= min:
			continue
		for j in range(0, 2 * n, 2):
			a2 = ((nl[j] - ml[i]) ** 2 + (nl[j + 1] - ml[i + 1]) ** 2) ** 0.5
			if a1 + a2 >= min:
				continue
			for h in range(0, 2 * k, 2):
				dist = a1 + a2 + ((nl[j] - kl[h]) ** 2 + (nl[j + 1] - kl[h + 1]) ** 2) ** 0.5
				if dist < min:
					min = dist
	print('%.8f' % min)


import sys
t = int(input())
for __ in range(t):
	xy = input().split()
	x = int(xy[0])
	y = int(xy[1])
	nmk = input().split()
	n = int(nmk[0])
	m = int(nmk[1])
	k = int(nmk[2])
	ab = [int(x) for x in input().split()]
	cd = [int(x) for x in input().split()]
	ef = [int(x) for x in input().split()]
	min1 = sys.maxsize
	for i in range(0, len(cd), 2):
		s = ((x - cd[i]) ** 2 + (y - cd[i + 1]) ** 2) ** 0.5
		if s >= min1:
			continue
		for j in range(0, len(ab), 2):
			si = ((cd[i] - ab[j]) ** 2 + (cd[i + 1] - ab[j + 1]) ** 2) ** 0.5
			if si + s > min1:
				continue
			for q in range(0, len(ef), 2):
				sis = ((ab[j] - ef[q]) ** 2 + (ab[j + 1] - ef[q + 1]) ** 2) ** 0.5
				x1 = s + si + sis
				if x1 < min1:
					min1 = x1
	min2 = sys.maxsize
	for i in range(0, len(ab), 2):
		d = ((x - ab[i]) ** 2 + (y - ab[i + 1]) ** 2) ** 0.5
		if d > min2:
			continue
		for j in range(0, len(cd), 2):
			di = ((ab[i] - cd[j]) ** 2 + (ab[i + 1] - cd[j + 1]) ** 2) ** 0.5
			if di + d > min2:
				continue
			for q in range(0, len(ef), 2):
				dis = ((cd[j] - ef[q]) ** 2 + (cd[j + 1] - ef[q + 1]) ** 2) ** 0.5
				y1 = d + di + dis
				if y1 < min2:
					min2 = y1
	if min1 <= min2:
		print(min1)
	else:
		print(min2)


import math

def cal(p1, p2):
	return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
for _ in range(int(input())):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	(n, m, k) = input().split()
	(n, m, k) = (int(n), int(m), int(k))
	a = input().split()
	b = input().split()
	c = input().split()
	(l1, l2) = ([], [])
	minl1 = 11111111111
	minl2 = 11111111111
	for i in range(0, n * 2, 2):
		a1 = cal([x, y], [int(a[i]), int(a[i + 1])])
		if minl2 < a1:
			continue
		for j in range(0, m * 2, 2):
			a2 = a1 + cal([int(a[i]), int(a[i + 1])], [int(b[j]), int(b[j + 1])])
			if minl2 < a2:
				continue
			for l in range(0, k * 2, 2):
				a3 = a2 + cal([int(b[j]), int(b[j + 1])], [int(c[l]), int(c[l + 1])])
				if a3 < minl2:
					minl2 = a3
	for i in range(0, m * 2, 2):
		a1 = cal([x, y], [int(b[i]), int(b[i + 1])])
		if minl1 < a1:
			continue
		for j in range(0, n * 2, 2):
			a2 = a1 + cal([int(b[i]), int(b[i + 1])], [int(a[j]), int(a[j + 1])])
			if minl1 < a2:
				continue
			for l in range(0, k * 2, 2):
				a3 = a2 + cal([int(a[j]), int(a[j + 1])], [int(c[l]), int(c[l + 1])])
				if a3 < minl1:
					minl1 = a3
	print(min(minl1, minl2))


t = int(input().strip())
d1 = [None] * 5000
for aa in range(t):
	(x, y) = map(int, input().strip().split())
	(n, m, o) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	c = list(map(int, input().strip().split()))
	e = list(map(int, input().strip().split()))
	min_so_far = float('inf')
	for i in range(n):
		d1[i] = (abs(a[2 * i] - x) ** 2 + abs(a[2 * i + 1] - y) ** 2) ** 0.5
		if d1[i] > min_so_far:
			continue
		for j in range(m):
			last = d1[i] + (abs(a[2 * i] - c[2 * j]) ** 2 + abs(a[2 * i + 1] - c[2 * j + 1]) ** 2) ** 0.5
			if last > min_so_far:
				continue
			for k in range(o):
				current = last + (abs(e[2 * k] - c[2 * j]) ** 2 + abs(e[2 * k + 1] - c[2 * j + 1]) ** 2) ** 0.5
				if current < min_so_far:
					min_so_far = current
	for i in range(m):
		d1[i] = (abs(c[2 * i] - x) ** 2 + abs(c[2 * i + 1] - y) ** 2) ** 0.5
		if d1[i] > min_so_far:
			continue
		for j in range(n):
			last = d1[i] + (abs(c[2 * i] - a[2 * j]) ** 2 + abs(c[2 * i + 1] - a[2 * j + 1]) ** 2) ** 0.5
			if last > min_so_far:
				continue
			for k in range(o):
				current = last + (abs(e[2 * k] - a[2 * j]) ** 2 + abs(e[2 * k + 1] - a[2 * j + 1]) ** 2) ** 0.5
				if current < min_so_far:
					min_so_far = current
	print(min_so_far)


import math
t = int(input())
for i in range(t):
	(x, y) = input().split(' ')
	x = int(x)
	y = int(y)
	inp = list(map(int, input().split()))
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	k = list(map(int, input().split()))
	total1 = 100000000000000
	for j in range(0, 2 * inp[0], 2):
		dis1 = math.sqrt((x - n[j]) * (x - n[j]) + (y - n[j + 1]) * (y - n[j + 1]))
		a = n[j]
		b = n[j + 1]
		if dis1 < total1 and dis1 < 10000000000 and (a < 1000000000) and (b < 1000000000):
			for l in range(0, 2 * inp[1], 2):
				dis2 = math.sqrt((a - m[l]) * (a - m[l]) + (b - m[l + 1]) * (b - m[l + 1]))
				c = m[l]
				d = m[l + 1]
				if dis2 < total1 and dis2 < 10000000000 and (dis1 + dis2 < total1):
					for p in range(0, 2 * inp[2], 2):
						dis = math.sqrt((c - k[p]) * (c - k[p]) + (d - k[p + 1]) * (d - k[p + 1]))
						if dis + dis1 + dis2 < total1:
							total1 = dis + dis1 + dis2
	total2 = 10000000000000
	for j in range(0, 2 * inp[1], 2):
		dis1 = math.sqrt((x - m[j]) * (x - m[j]) + (y - m[j + 1]) * (y - m[j + 1]))
		c1 = m[j]
		d1 = m[j + 1]
		if dis1 < total2 and dis1 < total1 and (dis1 < 10000000000):
			for l in range(0, 2 * inp[0], 2):
				dis2 = math.sqrt((c1 - n[l]) * (c1 - n[l]) + (d1 - n[l + 1]) * (d1 - n[l + 1]))
				a1 = n[l]
				b1 = n[l + 1]
				if dis2 < total2 and dis2 < total1 and (dis2 < 10000000000) and (dis1 + dis2 < total2):
					for p in range(0, 2 * inp[2], 2):
						dis = math.sqrt((a1 - k[p]) * (a1 - k[p]) + (b1 - k[p + 1]) * (b1 - k[p + 1]))
						if dis + dis1 + dis2 < total2:
							total2 = dis + dis1 + dis2
	if total1 < total2:
		print(total1)
	else:
		print(total2)


def main():
	from math import sqrt

	def dist(x1, y1, x2, y2):
		return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))

	def backdfs1(abd, cdd, efd, ans, sm, x, y, p):
		if p == 3:
			if sm < ans[0]:
				ans[0] = sm
			return
		elif p == 0:
			if sm >= ans[0]:
				return
			for i in range(len(abd)):
				d = dist(x, y, abd[i][0], abd[i][1])
				backdfs1(abd, cdd, efd, ans, sm + d, abd[i][0], abd[i][1], 1)
		elif p == 1:
			if sm >= ans[0]:
				return
			for i in range(len(cdd)):
				d = dist(x, y, cdd[i][0], cdd[i][1])
				backdfs1(abd, cdd, efd, ans, sm + d, cdd[i][0], cdd[i][1], 2)
		elif p == 2:
			if sm >= ans[0]:
				return
			for i in range(len(efd)):
				d = dist(x, y, efd[i][0], efd[i][1])
				backdfs1(abd, cdd, efd, ans, sm + d, efd[i][0], efd[i][1], 3)

	def backdfs2(abd, cdd, efd, ans1, sm, x, y, p):
		if p == 3:
			if sm < ans1[0]:
				ans1[0] = sm
			return
		elif p == 0:
			if sm >= ans1[0]:
				return
			for i in range(len(cdd)):
				d = dist(x, y, cdd[i][0], cdd[i][1])
				backdfs2(abd, cdd, efd, ans1, sm + d, cdd[i][0], cdd[i][1], 1)
		elif p == 1:
			if sm >= ans1[0]:
				return
			for i in range(len(abd)):
				d = dist(x, y, abd[i][0], abd[i][1])
				backdfs2(abd, cdd, efd, ans1, sm + d, abd[i][0], abd[i][1], 2)
		elif p == 2:
			if sm >= ans1[0]:
				return
			for i in range(len(efd)):
				d = dist(x, y, efd[i][0], efd[i][1])
				backdfs2(abd, cdd, efd, ans1, sm + d, efd[i][0], efd[i][1], 3)
	for _ in range(int(input().strip())):
		(x, y) = map(int, input().strip().split())
		(n, m, K) = map(int, input().strip().split())
		ab = list(map(int, input().strip().split()))
		cd = list(map(int, input().strip().split()))
		ef = list(map(int, input().strip().split()))
		abd = []
		for i in range(0, 2 * n, 2):
			abd.append([ab[i], ab[i + 1]])
		cdd = []
		for i in range(0, 2 * m, 2):
			cdd.append([cd[i], cd[i + 1]])
		efd = []
		for i in range(0, 2 * K, 2):
			efd.append([ef[i], ef[i + 1]])
		ans = [1000000000000]
		ans1 = [1000000000000]
		backdfs1(abd, cdd, efd, ans, 0, x, y, 0)
		backdfs2(abd, cdd, efd, ans1, 0, x, y, 0)
		print(min(ans[0], ans1[0]))
main()


for i in range(int(input())):
	(x, y) = list(map(int, input().split()))
	(n, m, k) = list(map(int, input().split()))
	ab = []
	cd = []
	ef = []
	a1b1 = list(map(int, input().split()))
	i = 0
	l = []
	while i < 2 * n:
		if i % 2 == 0:
			l.append(a1b1[i])
		else:
			l.append(a1b1[i])
			ab.append(l)
			l = []
		i += 1
	c1d1 = list(map(int, input().split()))
	i = 0
	l = []
	while i < 2 * m:
		if i % 2 == 0:
			l.append(c1d1[i])
		else:
			l.append(c1d1[i])
			cd.append(l)
			l = []
		i += 1
	e1f1 = list(map(int, input().split()))
	i = 0
	l = []
	while i < 2 * k:
		if i % 2 == 0:
			l.append(e1f1[i])
		else:
			l.append(e1f1[i])
			ef.append(l)
			l = []
		i += 1
	ans = 10 ** 11
	for i in ab:
		d = 0
		(a, b) = (i[0], i[1])
		d1 = pow(pow(x - a, 2) + pow(y - b, 2), 0.5)
		if d1 > ans:
			continue
		for j in cd:
			d2 = d1
			(c, d) = (j[0], j[1])
			d2 += pow(pow(a - c, 2) + pow(b - d, 2), 0.5)
			if d2 > ans:
				continue
			for k in ef:
				d3 = d2
				(e, f) = (k[0], k[1])
				d3 += pow(pow(c - e, 2) + pow(d - f, 2), 0.5)
				if d3 < ans:
					ans = d3
	for i in cd:
		d = 0
		(c, d) = (i[0], i[1])
		d1 = pow(pow(x - c, 2) + pow(y - d, 2), 0.5)
		if d1 > ans:
			continue
		for j in ab:
			d2 = d1
			(a, b) = (j[0], j[1])
			d2 += pow(pow(a - c, 2) + pow(b - d, 2), 0.5)
			if d2 > ans:
				continue
			for k in ef:
				d3 = d2
				(e, f) = (k[0], k[1])
				d3 += pow(pow(a - e, 2) + pow(b - f, 2), 0.5)
				if d3 < ans:
					ans = d3
	print(ans)


from math import pow, sqrt
for _ in range(int(input())):
	a1 = []
	b1 = []
	a2 = []
	b2 = []
	a3 = []
	b3 = []
	c = [1000000000000000]
	(x, y) = map(int, input().split())
	(n, m, k) = list(map(int, input().split()))
	e = list(map(int, input().split()))
	f = list(map(int, input().split()))
	g = list(map(int, input().split()))
	for i in range(len(e)):
		if i % 2 == 0:
			a1.append(e[i])
		else:
			b1.append(e[i])
	for i in range(len(f)):
		if i % 2 == 0:
			a2.append(f[i])
		else:
			b2.append(f[i])
	for i in range(len(g)):
		if i % 2 == 0:
			a3.append(g[i])
		else:
			b3.append(g[i])
	for i in range(len(a1)):
		x1 = pow(x - a1[i], 2)
		y1 = pow(y - b1[i], 2)
		t = sqrt(x1 + y1)
		if t < min(c):
			for j in range(len(a2)):
				x1 = pow(a1[i] - a2[j], 2)
				y1 = pow(b1[i] - b2[j], 2)
				t1 = sqrt(x1 + y1)
				if t + t1 < min(c):
					for k in range(len(a3)):
						l = 0
						x1 = pow(a2[j] - a3[k], 2)
						y1 = pow(b2[j] - b3[k], 2)
						t2 = sqrt(x1 + y1)
						l = t + t1 + t2
						if l < min(c):
							c.append(l)
	for i in range(len(a2)):
		x1 = pow(x - a2[i], 2)
		y1 = pow(y - b2[i], 2)
		t = sqrt(x1 + y1)
		if t < min(c):
			for j in range(len(a1)):
				x1 = pow(a2[i] - a1[j], 2)
				y1 = pow(b2[i] - b1[j], 2)
				t1 = sqrt(x1 + y1)
				if t + t1 < min(c):
					for k in range(len(a3)):
						l = 0
						x1 = pow(a1[j] - a3[k], 2)
						y1 = pow(b1[j] - b3[k], 2)
						t2 = sqrt(x1 + y1)
						l = t + t1 + t2
						if l < min(c):
							c.append(l)
	print(min(c))


import math

def calculateDistance(x1, y1, x2, y2):
	dist = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	return dist
for i in range(int(input())):
	(X, Y) = input().split()
	x = int(X)
	y = int(Y)
	(N, M, K) = input().split()
	n = int(N)
	m = int(M)
	k = int(K)
	lst_n = list(map(int, input().split()))
	lst_m = list(map(int, input().split()))
	lst_k = list(map(int, input().split()))
	min_n = 9999999999999999
	min_m = 9999999999999999
	for j in range(1, 2 * n, 2):
		nn = calculateDistance(x, y, lst_n[j - 1], lst_n[j])
		if nn > min_n:
			continue
		for a in range(1, 2 * m, 2):
			mm = calculateDistance(lst_n[j - 1], lst_n[j], lst_m[a - 1], lst_m[a])
			to = mm + nn
			if to > min_n:
				continue
			for b in range(1, 2 * k, 2):
				ans_n = to + calculateDistance(lst_m[a - 1], lst_m[a], lst_k[b - 1], lst_k[b])
				if ans_n < min_n:
					min_n = ans_n
	for a in range(1, 2 * m, 2):
		mmm = calculateDistance(x, y, lst_m[a - 1], lst_m[a])
		if mmm > min_m:
			continue
		for j in range(1, 2 * n, 2):
			nnn = calculateDistance(lst_m[a - 1], lst_m[a], lst_n[j - 1], lst_n[j])
			to_n = mmm + nnn
			if to_n > min_m:
				continue
			for b in range(1, 2 * k, 2):
				ans_m = to_n + calculateDistance(lst_n[j - 1], lst_n[j], lst_k[b - 1], lst_k[b])
				if ans_m < min_m:
					min_m = ans_m
	if min_n > min_m:
		print(min_m)
	else:
		print(min_n)


import math

def dis(x, y, x1, y1):
	x = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)
	return x
t = int(input())
while t > 0:
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	(n, m, k) = input().split()
	n = int(n)
	m = int(m)
	k = int(k)
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	c = list(map(int, input().strip().split()))
	m = 10 ** 20
	m1 = 10 ** 20
	for i in range(0, len(a) - 1, 2):
		d1 = dis(x, y, a[i], a[i + 1])
		if d1 > m:
			continue
		for j in range(0, len(b) - 1, 2):
			d2 = dis(a[i], a[i + 1], b[j], b[j + 1])
			d21 = d2 + d1
			if d21 > m:
				continue
			for k in range(0, len(c) - 1, 2):
				v = dis(b[j], b[j + 1], c[k], c[k + 1])
				d3 = d1 + d2 + v
				if (i == 0 and j == 0) and k == 0:
					m = d3
				elif d3 > m:
					continue
				elif m > d3:
					m = d3
	for i in range(0, len(b) - 1, 2):
		d1 = dis(x, y, b[i], b[i + 1])
		if d1 > m:
			continue
		for j in range(0, len(a) - 1, 2):
			d2 = dis(a[j], a[j + 1], b[i], b[i + 1])
			d12 = d1 + d2
			if d12 > m:
				continue
			for k in range(0, len(c) - 1, 2):
				v = dis(a[j], a[j + 1], c[k], c[k + 1])
				d3 = d1 + d2 + v
				if d3 > m:
					continue
				elif m > d3:
					m = d3
	print(m)
	t = t - 1


t = int(input())

def dis(a, b):
	return pow((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2, 0.5)
while t > 0:
	t -= 1
	(x, y) = list(map(int, input().split()))
	(n, m, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	A = []
	for i in range(0, n):
		A.append((a[2 * i], a[2 * i + 1]))
	B = []
	for i in range(0, m):
		B.append((b[2 * i], b[2 * i + 1]))
	C = []
	for i in range(0, k):
		C.append((c[2 * i], c[2 * i + 1]))
	p = (x, y)
	mn = dis(A[0], B[0]) + dis(p, A[0]) + dis(B[0], C[0])
	for i in A:
		dpi = dis(p, i)
		if dpi < mn:
			for j in B:
				dpj = dis(p, j)
				if dpj < mn:
					dij = dis(i, j)
					if dij + dpi < mn or dij + dpj < mn:
						for k in C:
							d = min(dpi + dis(j, k), dpj + dis(i, k)) + dij
							if mn > d:
								mn = d
	print(mn)


import math
for t in range(int(input())):
	(x, y) = [float(i) for i in input().split()]
	(n, m, k) = [int(i) for i in input().split()]
	z = input().split()
	(a, c, e) = ([], [], [])
	for i in range(0, 2 * n, 2):
		a.append((float(z[i]), float(z[i + 1])))
	z = input().split()
	for i in range(0, 2 * m, 2):
		c.append((float(z[i]), float(z[i + 1])))
	z = input().split()
	for i in range(0, 2 * k, 2):
		e.append((float(z[i]), float(z[i + 1])))
	mini = -1
	for i in a:
		curri = math.sqrt((x - i[0]) ** 2 + (y - i[1]) ** 2)
		if curri > mini and mini != -1:
			continue
		for j in c:
			currj = curri + math.sqrt((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)
			if currj > mini and mini != -1:
				continue
			for l in e:
				currk = currj + math.sqrt((j[0] - l[0]) ** 2 + (j[1] - l[1]) ** 2)
				if currk > mini and mini != -1:
					continue
				else:
					mini = currk
	for i in c:
		curri = math.sqrt((x - i[0]) ** 2 + (y - i[1]) ** 2)
		if curri > mini:
			continue
		for j in a:
			currj = curri + math.sqrt((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)
			if currj > mini:
				continue
			for l in e:
				currk = currj + math.sqrt((j[0] - l[0]) ** 2 + (j[1] - l[1]) ** 2)
				if currk > mini:
					continue
				else:
					mini = currk
	print(mini)


import math
t = int(input())
while t:
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	ab = list(map(int, input().split()))
	cd = list(map(int, input().split()))
	ef = list(map(int, input().split()))
	m1 = float('inf')
	m2 = float('inf')
	d11 = []
	d22 = []
	for i in range(0, 2 * n, 2):
		d1 = math.sqrt((x - ab[i]) ** 2 + (y - ab[i + 1]) ** 2)
		if d1 >= m1:
			continue
		else:
			for j in range(0, 2 * m, 2):
				d2 = math.sqrt((ab[i] - cd[j]) ** 2 + (ab[i + 1] - cd[j + 1]) ** 2)
				if d1 + d2 >= m1:
					continue
				else:
					for l in range(0, 2 * k, 2):
						d3 = math.sqrt((cd[j] - ef[l]) ** 2 + (cd[j + 1] - ef[l + 1]) ** 2)
						m1 = min(m1, d1 + d2 + d3)
	for i in range(0, 2 * m, 2):
		d1 = math.sqrt((x - cd[i]) ** 2 + (y - cd[i + 1]) ** 2)
		if d1 >= m2:
			continue
		else:
			for j in range(0, 2 * n, 2):
				d2 = math.sqrt((cd[i] - ab[j]) ** 2 + (cd[i + 1] - ab[j + 1]) ** 2)
				if d1 + d2 >= m2:
					continue
				else:
					for l in range(0, 2 * k, 2):
						d3 = math.sqrt((ab[j] - ef[l]) ** 2 + (ab[j + 1] - ef[l + 1]) ** 2)
						d22.append(d1 + d2 + d3)
						m2 = min(m2, d1 + d2 + d3)
	print(round(min(m1, m2), 10))
	t -= 1


def find(x1, y1, x2, y2):
	return math.sqrt((y2 - y1) ** 2 + (x2 - x1) ** 2)
t = int(input())
import math
while t:
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = list(map(int, input().split()))
	e = list(map(int, input().split()))
	i = 0
	arr1 = []
	arr2 = []
	arr3 = []
	while i < len(a):
		arr1.append((a[i], a[i + 1]))
		i += 2
	i = 0
	while i < len(c):
		arr2.append((c[i], c[i + 1]))
		i += 2
	i = 0
	while i < len(e):
		arr3.append((e[i], e[i + 1]))
		i += 2
	minn = 10000000000000000000000000000
	for i in range(len(arr1)):
		(x1, y1) = arr1[i]
		dis1 = find(x, y, x1, y1)
		if dis1 > minn:
			continue
		for j in range(len(arr2)):
			(x2, y2) = arr2[j]
			dis2 = find(x1, y1, x2, y2)
			if dis1 + dis2 > minn:
				continue
			for k in range(len(arr3)):
				(x3, y3) = arr3[k]
				dis3 = find(x2, y2, x3, y3)
				if dis1 + dis2 + dis3 < minn:
					minn = dis1 + dis2 + dis3
	for i in range(len(arr2)):
		(x2, y2) = arr2[i]
		dis1 = find(x, y, x2, y2)
		if dis1 > minn:
			continue
		for j in range(len(arr1)):
			(x1, y1) = arr1[j]
			dis2 = find(x2, y2, x1, y1)
			if dis1 + dis2 > minn:
				continue
			for k in range(len(arr3)):
				(x3, y3) = arr3[k]
				dis3 = find(x1, y1, x3, y3)
				if dis1 + dis2 + dis3 < minn:
					minn = dis1 + dis2 + dis3
	print(round(minn, 10))
	t -= 1


import math

def distance(x1, y1, x2, y2):
	return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
t = int(input())
while t:
	t -= 1
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	tem = list(map(int, input().split()))
	a = []
	b = []
	for i in range(0, 2 * n, 2):
		a.append(tem[i])
		b.append(tem[i + 1])
	tem = list(map(int, input().split()))
	c = []
	d = []
	for i in range(0, 2 * m, 2):
		c.append(tem[i])
		d.append(tem[i + 1])
	tem = list(map(int, input().split()))
	e = []
	f = []
	for i in range(0, 2 * k, 2):
		e.append(tem[i])
		f.append(tem[i + 1])
	tilln = 0
	tillm = 0
	mink = 0
	inmk1 = inmk2 = inmk3 = imnk1 = imnk2 = imnk3 = 0
	ik2 = 0
	minim = 1000000000000
	for i in range(n):
		inmk1 = distance(x, y, a[i], b[i])
		if inmk1 > minim:
			continue
		for j in range(m):
			imnk1 = distance(x, y, c[j], d[j])
			ik2 = distance(a[i], b[i], c[j], d[j])
			if imnk1 + ik2 > minim and inmk1 + ik2 > minim:
				continue
			for l in range(k):
				minim = min(inmk1 + ik2 + distance(c[j], d[j], e[l], f[l]), minim, imnk1 + ik2 + distance(a[i], b[i], e[l], f[l]))
	print('{:.10f}'.format(round(minim, 10)))


def dist(x1, y1, x2, y2):
	return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5

def get_min_dist(x, y, n, m, k, n_arr, m_arr, k_arr):
	n_coords = []
	for i in range(0, 2 * n, 2):
		n_coords.append((n_arr[i], n_arr[i + 1]))
	m_coords = []
	for i in range(0, 2 * m, 2):
		m_coords.append((m_arr[i], m_arr[i + 1]))
	k_coords = []
	for i in range(0, 2 * k, 2):
		k_coords.append((k_arr[i], k_arr[i + 1]))
	min_start_n = dist(x, y, n_coords[0][0], n_coords[0][1]) + dist(n_coords[0][0], n_coords[0][1], m_coords[0][0], m_coords[0][1]) + dist(m_coords[0][0], m_coords[0][1], k_coords[0][0], k_coords[0][1])
	for i in range(n):
		d1 = dist(x, y, n_coords[i][0], n_coords[i][1])
		if d1 < min_start_n:
			for j in range(m):
				d2 = dist(n_coords[i][0], n_coords[i][1], m_coords[j][0], m_coords[j][1])
				if d1 + d2 < min_start_n:
					for l in range(k):
						d3 = dist(m_coords[j][0], m_coords[j][1], k_coords[l][0], k_coords[l][1])
						if d1 + d2 + d3 < min_start_n:
							min_start_n = d1 + d2 + d3
	min_start_m = dist(x, y, m_coords[0][0], m_coords[0][1]) + dist(n_coords[0][0], n_coords[0][1], m_coords[0][0], m_coords[0][1]) + dist(n_coords[0][0], n_coords[0][1], k_coords[0][0], k_coords[0][1])
	for i in range(m):
		d1 = dist(x, y, m_coords[i][0], m_coords[i][1])
		if d1 < min_start_m:
			for j in range(n):
				d2 = dist(n_coords[j][0], n_coords[j][1], m_coords[i][0], m_coords[i][1])
				if d1 + d2 < min_start_m:
					for l in range(k):
						d3 = dist(n_coords[j][0], n_coords[j][1], k_coords[l][0], k_coords[l][1])
						if d1 + d2 + d3 < min_start_m:
							min_start_m = d1 + d2 + d3
	return min(min_start_n, min_start_m)
T = int(input())
for _ in range(T):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	n_arr = list(map(int, input().split()))
	m_arr = list(map(int, input().split()))
	k_arr = list(map(int, input().split()))
	ans = get_min_dist(x, y, n, m, k, n_arr, m_arr, k_arr)
	print(ans)


import math
for _ in range(int(input())):
	mn = math.inf
	(x, y) = map(int, input().split())
	(n, m, k) = 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(n):
		x1 = a[2 * i]
		y1 = a[2 * i + 1]
		lng1 = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
		if lng1 < mn:
			for j in range(m):
				x2 = b[2 * j]
				y2 = b[2 * j + 1]
				length1 = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 + lng1
				if length1 <= mn:
					for ij in range(k):
						x3 = c[2 * ij]
						y3 = c[2 * ij + 1]
						length3 = length1 + ((x3 - x2) ** 2 + (y3 - y2) ** 2) ** 0.5
						mn = min(length3, mn)
	for j in range(m):
		x2 = b[2 * j]
		y2 = b[2 * j + 1]
		lng2 = ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5
		if lng2 < mn:
			for i in range(n):
				x1 = a[2 * i]
				y1 = a[2 * i + 1]
				length2 = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 + lng2
				if length2 < mn:
					for ij in range(k):
						x3 = c[2 * ij]
						y3 = c[2 * ij + 1]
						length4 = length2 + ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
						mn = min(length4, mn)
	print(mn)


def distance(x, y):
	return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) ** 0.5
MAX = 10 ** 20
t = int(input())
for _ in range(t):
	(x, y) = map(int, input().split())
	(n, m, k) = map(int, input().split())
	nSetOfPoints = list(map(int, input().split()))
	mSetOfPoints = list(map(int, input().split()))
	kSetOfPoints = list(map(int, input().split()))
	nSetOfPoints = [[nSetOfPoints[i], nSetOfPoints[i + 1]] for i in range(0, 2 * n, 2)]
	mSetOfPoints = [[mSetOfPoints[i], mSetOfPoints[i + 1]] for i in range(0, 2 * m, 2)]
	kSetOfPoints = [[kSetOfPoints[i], kSetOfPoints[i + 1]] for i in range(0, 2 * k, 2)]
	(ans1, ans2, ans3, ans4) = (0, 0, 0, 0)
	previousAnswer = MAX
	for i in range(n):
		ans1 = distance([x, y], nSetOfPoints[i])
		if ans1 < previousAnswer:
			for j in range(m):
				ans2 = distance(nSetOfPoints[i], mSetOfPoints[j])
				if ans1 + ans2 < previousAnswer:
					for h in range(k):
						ans3 = distance(mSetOfPoints[j], kSetOfPoints[h])
						if ans1 + ans2 + ans3 < previousAnswer:
							previousAnswer = ans1 + ans2 + ans3
	for i in range(m):
		ans1 = distance([x, y], mSetOfPoints[i])
		if ans1 < previousAnswer:
			for j in range(n):
				ans2 = distance(mSetOfPoints[i], nSetOfPoints[j])
				if ans1 + ans2 < previousAnswer:
					for h in range(k):
						ans3 = distance(nSetOfPoints[j], kSetOfPoints[h])
						if ans1 + ans2 + ans3 < previousAnswer:
							previousAnswer = ans1 + ans2 + ans3
	print('%.10f' % previousAnswer)


from math import sqrt

def distance(a, b):
	return sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)

def getDistance(point, AB, CD, EF, N, M, K):
	AB.sort(key=lambda x: distance(x, point))
	CD.sort(key=lambda x: distance(x, point))
	ans = 10 ** 10
	for i in range(N):
		firstdist = distance(point, AB[i])
		if firstdist > ans:
			break
		CD_copy = CD[:]
		CD_copy.sort(key=lambda x: distance(AB[i], x))
		for j in range(min(15, M)):
			seconddist = firstdist + distance(AB[i], CD_copy[j])
			if seconddist > ans:
				break
			EF_copy = EF[:]
			EF_copy.sort(key=lambda x: distance(CD_copy[j], x))
			totaldist = seconddist + distance(CD_copy[j], EF_copy[0])
			ans = min(totaldist, ans)
	for i in range(M):
		firstdist = distance(point, CD[i])
		if firstdist > ans:
			break
		AB_copy = AB[:]
		AB_copy.sort(key=lambda x: distance(CD[i], x))
		for j in range(min(15, N)):
			seconddist = firstdist + distance(CD[i], AB_copy[j])
			if seconddist > ans:
				break
			EF_copy = EF[:]
			EF_copy.sort(key=lambda x: distance(AB_copy[j], x))
			totaldist = seconddist + distance(AB_copy[j], EF_copy[0])
			ans = min(totaldist, ans)
	return ans
T = int(input().rstrip())
for _ in range(T):
	point = tuple(map(int, input().rstrip().split()))
	(N, M, K) = map(int, input().rstrip().split())
	arr = list(map(int, input().rstrip().split()))
	AB = [(arr[i], arr[i + 1]) for i in range(0, 2 * N, 2)]
	arr = list(map(int, input().rstrip().split()))
	CD = [(arr[i], arr[i + 1]) for i in range(0, 2 * M, 2)]
	arr = list(map(int, input().rstrip().split()))
	EF = [(arr[i], arr[i + 1]) for i in range(0, 2 * K, 2)]
	print(getDistance(point, AB, CD, EF, N, M, K))