Question
Essence of Numbers
You have been tasked by the Digitopia council to calculate the sum of the essences for all numbers from 1 to N.
Can you solve this and present the total essence sum?
In the land of Digitopia, the scholars have uncovered an ancient technique called the “Essence of Numbers.”
This essence is revealed by repeatedly summing the digits of a number until only a single digit remains.
For example, to uncover the essence of 872:
- First, sum the digits: 8 + 7 + 2 = 17.
- Then, sum the digits of 17: 1 + 7 = 8.
You have been tasked by the Digitopia council to calculate the sum of the essences for all numbers from 1 to N.
Can you solve this and present the total essence sum?
Input
The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of a single line of input, containing one integer N.
Each test case consists of a single line of input, containing one integer N.
Output
For each test case, output on a new line the sum of the essences values of integers from 1 to N.
Example
Sample Input
2
5
12
Sample Output
15
51
Explanation
Test case 1: In this case the answer is simply 1 + 2 + 3 + 4 + 5 = 15.
Test case 2: In this case we have to find the sum of essences of every integer from 1 to 12.
1 through 9 are their own origins.
The origin of 10 is 1, since 1 + 0 = 1.
The origin of 11 is 2, since 1 + 1 = 2.
The origin of 12 is 3, since 1 + 2 = 3.
So, the answer is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 2 + 3 = 51.
2
5
12
Sample Output
15
51
Explanation
Test case 1: In this case the answer is simply 1 + 2 + 3 + 4 + 5 = 15.
Test case 2: In this case we have to find the sum of essences of every integer from 1 to 12.
1 through 9 are their own origins.
The origin of 10 is 1, since 1 + 0 = 1.
The origin of 11 is 2, since 1 + 1 = 2.
The origin of 12 is 3, since 1 + 2 = 3.
So, the answer is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 2 + 3 = 51.