A group of cp enthusiastic students from University of Dhaka were on a fun journey. They brought along a special array passport called from their university. This passport was a list of distinct numbers from to .
As they explored, they discovered a bunch of mysterious boxes. Each box had a number written on it. There were of these boxes in total. The students knew that these numbers held the key to unlocking the secrets inside the boxes.
To open the boxes and reveal the treasures hidden inside, they had to follow a set of rules. First, they sorted their array passport carefully in ascending order. Then, they needed to reverse part of the sorted list, starting from index and going to the end of the list.
After each time they followed these rules, they discovered a special code or password that unlocked each of the mystery boxes. They calculated this password by adding up the numbers in their list, but each number had to be multiplied by its position in the list.
Formally, the password of the box written the number on top of it is calculated as follows:
Sort the array
Feeling very tired from their long journey, they came to you for help in figuring out how to open the boxes. They showed you their special array passport and the numbers on each of the mystery boxes. Can you give them a hand?
The problem contains multiple test cases.
The first line contains the number of test cases . The description of the test cases follows-
The first line of each test case contains a single integer
The second line of each test case contains space-separated distinct integer from to denoting the array passport .
The next line contains an integer denoting the number of boxes.
Each of the next lines contain an integer
It is guaranteed that the sum of over all test cases does not exceed . It is also guaranteed that the sum of over all test cases does not exceed .
For each of the boxes, output the password in a new line.
1 7 5 4 7 3 6 1 2 5 4 3 6 7 5
130 120 139 140 136
In the sample input, the first box contains the number .
After sorting the array: it becomes
Reversing the segment it becomes
So, the password is