Sum Of All

4.8

4 votes
Math, Algorithms, Modulus Arithmetic, Number Theory
Problem

You are given a number. You want to compute the sum of all possible resulting numbers after applying the magic operation.
In a magic operation, you pick a non-empty subsequence from this number, then take these digits out of the number. The remaining digits then fill in the gap, and the number after the magic operation is the integer that is left.

For eg: Let's say the number is 12345. One of the subsequences of this number is 24So after removing this subsequence, the resulting number is 135.
Leading zeros are allowed in the resulting number (number after applying the magic operation). When all digits are removed, the number is considered to be 0.

Input Format:

  • The first line contains one integer T  the number of test cases. Then T test cases follow.
  • The first and only line of each test case contains a single integer N.

Output Format:

For each test case output in a seperate line:
The sum of all possible resulting numbers after applying the magic operation modulo (109+7).

Constraints:

  • 1T105
  • 1N10100000
  • It is guaranteed that sum of N over all test cases doesn't exceed 10100000

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Let's consider the first test case.
Non-Empty Subsequences we can remove from the given number are :  2,0,3,20,23,03,203
After removing these digits, the resulting numbers are 03,23,20,3,0,2,0 respectively. The sum of all the resulting numbers is 51 which is the answer.

Editor Image

?