Stud Sahil and Live-In <3

5

1 votes
Easy
Problem

Stud Sahil and his girlfriend X(??) are trying to find a new place in Kamand to live together as a couple. They are in a dilemma. Their friends live in different parts of the village and they want to live close to all of them. All houses in Kamand lie on a horizontal line(X-axis). There is a house on every lattice(integer) point on  this line. You are given the x-coordinates of all the friends' houses along that line in an array A of n integers {A1, A2, ....An}.

Your task is to find the sum of all the distinct coordinates where Sahil and X can select their house so that the total of the distances between their(Sahil and X) and each friend's house is minimized. Have a look at the sample I/O for better understanding.

Note that they can also live at their friends' place if required.

Since the answer can be very large, print the answer MODULO 109 + 7.

Input

The first line contains the total number of test cases T. Each of the test case contains two lines. The first line of each test case contains the size of the array N. The next line contains N space separated integers, denoting the x-co-ordinates of their friends' houses.

Since the input file can be very large, it is advisable to use fast I/O.

Output

For each test case, print the answer in a single line.

Constraints

  • 1 <= T <= 10
  • 1 <= N <= 105
  • -1012 <= Ai <= 1012

Subtasks

Subtask #1 (20 points):

  • -103 <= Ai <= 103

  • 1<=N<=1000

Subtask #2 (80 points):

  • Original Constraints.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the second test case:

When the couple chooses a house at x=3, the sum of the distances will be

|3-3|+|3-(-10)|+|3-4|+|3-5|+|3-2|=17. Note that this is the only value of x where the sum is minimum.

Editor Image

?