Under construction

Still being built. Things may change

Equanimous

Time limit2sMemory limit256 MB

Summary
For each query (l, r), the task sums the integers m in [l, r] grouped by f(m), the minimal absolute signed-digit sum, for values 0 to 9, modulo 1e9+7.
Level

Hard8 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Problem

Alice, Bob, and Eve play a game on craft paper. Each time Eve names a natural number, Alice and Bob write that number in decimal on their own paper, put a plus or minus sign before each digit, and evaluate the expression they wrote. The player with the smaller absolute value wins. If the absolute values are equal, the game is a draw and they play one more round.

If they are smart, the game never ends. So they turn to the optimal solution of the puzzle. Let f(m)f(m) be the minimal absolute value that can be built from mm. Find f(m)f(m) for l≤m≤rl \leq m \leq r.

They also set a puzzle for you. For several queries (l,r)(l, r), find the sum of all integers mm with l≤m≤rl \leq m \leq r and f(m)=kf(m) = k, for each k=0,1,…,9k = 0, 1, \ldots, 9. Report the answers modulo 109+710^9 + 7.

Input

The first line contains one integer nn (1≤n≤50001 \leq n \leq 5000), the number of queries. Each of the next nn lines contains two integers ll and rr (1≤l≤r≤101001 \leq l \leq r \leq 10^{100}).

Output

For each query, print one line with ten space-separated integers. The kk-th integer, counting from k=0k = 0 to k=9k = 9, is the sum of all mm with l≤m≤rl \leq m \leq r and f(m)=kf(m) = k, modulo 109+710^9 + 7.

Hint

The digits of 1926081719260817 are {1,9,2,6,0,8,1,7}\{1, 9, 2, 6, 0, 8, 1, 7\}, which can build the expression (+1−9−2−6+0+8+1+7)(+1-9-2-6+0+8+1+7). Its value and absolute value are both 00.

The digits of 1926081819260818 are {1,9,2,6,0,8,1,8}\{1, 9, 2, 6, 0, 8, 1, 8\}, which can build the expression (+1−9+2+6−0−8−1+8)(+1-9+2+6-0-8-1+8). Its value is −1-1 and its absolute value is 11.

Examples1

  1. Example 1

    Input
    7
    1 10
    11 50
    51 100
    101 500
    501 1000
    19260817 19260818
    1234567890123456789 1234567890987654321
    
    Expected output
    0 11 2 3 4 5 6 7 8 9
    110 210 211 193 166 180 84 47 19 0
    385 770 579 497 424 310 306 243 171 90
    19080 34666 27312 19047 10615 5490 2594 1097 299 0
    43695 81005 67134 55962 46289 35085 23872 13924 6385 1899
    19260817 19260818 0 0 0 0 0 0 0 0
    230833519 749351908 0 0 0 0 0 0 0 0