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UBMISSIONSALL SUBMISSIONS
Read problems statements in Mandarin Chinese and Russian.
Churu is working as a data scientist in Coderpur. He works on a lot of data on the daily basis. One day, he found an interesting problem, which was very easy to solve for small data but was getting more complex with increasing number of data points. So, Churu needs your help in solving this problem.
Given a set S of N non-negative integers (Some integers might occur more than once in the set), find out the value of SETDIFF(S).
Mountain View
Where max(s) represents the maximum value in set s whereas min(s) represents the minimum value in the set s.
As value of SETDIFF(S) can be very large, print it modulo (109 + 7) .
Input
First line of input contains an integer T denoting number of test cases.
For each test case, first line will contain an integer N denoting number of elements in set S.
Next line contains N space separated integers denoting the set S.
Output
For each test case, print a single integer representing the answer of that test case.
Note
Two subsets will be called different if there exists an index i such that S[i] is occurs in one of the subset and not in another.
Constraints
Subtask #1: 20 points
1 ≤ T ≤ 5, 1 ≤ N ≤ 1000, 0 ≤ value in set ≤ 109
Subtask #2: 25 points
1 ≤ T ≤ 5, 1 ≤ N ≤ 105, 0 ≤ value in set ≤ 1000
Subtask #3: 55 points
1 ≤ T ≤ 5, 1 ≤ N ≤ 105, 0 ≤ value in set ≤ 109
Example
Input:
3
2
1 2
3
1 2 3
4
1 2 3 4