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$.

Difficulty: MEDIUM_HARD

Solutions:
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

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


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


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


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


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