


For the given array [5, 8, 4, 9]
The sum of the elements of the array will be
5 + 8 + 4 + 9 = 26.
Since 26 is not a single-digit number, we will again take the sum of the digits of 26.
2 + 6 = 8.
Now 8 is a single-digit number. So we will stop here and return 8.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains a single integer ‘N’, representing the size of the array.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the given array.
For each test case, print a single-digit integer representing the sum of the array.
Output for each test case will be printed in a separate line.
You are not required to print anything, it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 10^3
0 <= arr[i] <= 9
It is guaranteed that the sum of ‘N’ over all test cases doesn’t exceed 10^5.
Time Limit: 1 sec.
We will iterate from left to right and will calculate the sum of the elements and if the sum becomes a double-digit number we will make it a single-digit number according to the steps given in the problem statement.