

The first line of input contains a single integer 'T', representing the number of test cases.
The first line of each test case contains an integer ‘N’ representing the number of elements in the array.
The second line of each test contains ‘N’ space-separated integers representing the elements of the array ‘arr’.
For each test case, output a single line containing ‘N’ space-separated integers representing the sum of previous greater elements for each element of the array.
You don't need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10 ^ 4
1 <= arr[i] <= 10 ^ 3
Time Limit: 1 sec.
The idea is to calculate the sum of all elements greater than the current element by making nested iterations one to traverse the array and one to check the previous elements for the given condition.
We can use Binary Indexed Tree to optimize the range sum query.
Sum of Shadows
Chocolate and Sweetness
Chocolate and Sweetness
Chocolate and Sweetness
Chocolate and Sweetness
Range Minimum Query
Range Minimum Query
Range Minimum Query
Range Minimum Query
Ninja and Tree
Distinct Queries on Tree