You are given a sequence of integersof length . You have to split these integers into pairs; each pair will represent the coordinates of a point on a plane. Each number from the sequence should become the or coordinate of exactly one point. Note that some points can be equal.
After the points are formed, you have to choose a paththat starts from one of these points, ends at one of these points, and visits all points at least once.
The length of pathis the sum of distances between all adjacent points on the path. In this problem, the distance between two points and is defined as .
Your task is to formpoints and choose a path in such a way that the length of path is minimized.
The first line contains a single integer( ) — the number of testcases.
The first line of each testcase contains a single integer( ) — the number of points to be formed.
The next line containsintegers ( ) — the description of the sequence .
For each testcase, print the minimum possible length of pathin the first line.
In the-th of the following lines, print two integers and — the coordinates of the point that needs to be visited at the -th position.
If there are multiple answers, print any of them.
9 10 1 15 5 20 20 20 10 30 10 30
In the first testcase, for instance, you can form pointsand and start the path from the first point and end it at the second point. Then the length of the path will be .
In the second testcase, you can form points, , and , and visit them in that exact order. Then the length of the path will be .
# Function to calculate the minimum possible length of the path and the points to visit
def minimum_path_length(n, a):
min_length = 0
points = 
for i in range(n):
x = a[i]
y = a[i + n]
min_length += (x – a) + (a[n] – x)
return min_length, points
# Read the number of test cases
t = int(input())
# Iterate through each test case
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
min_length, points = minimum_path_length(n, a)
for point in points: