This page is still under construction.

Parts of this page are still being built. What you see may change.

Sum of all numbers made from even digits

Time limit1sMemory limit128 MB

Summary
Add up every distinct number that can be formed from the available copies of digits 2, 4, 6 and 8, modulo 1,000,000,007.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

The positive closure of a set of strings is the set of all finite, non-empty strings obtained by concatenating members of that set, where the same member may be used more than once. Here the members are single digits, so every element of the closure is a number.

Only the four even digits 2, 4, 6, 8 are usable, and for each of them the input gives how many copies are available. Build every number that can be written without exceeding those counts, count each distinct number once, and add them all up. The sum can grow large, so print it modulo 1,000,000,007.

Suppose two copies of 2 and one copy of 4 are available. Exactly eight distinct numbers can be written: 2, 4, 22, 24, 42, 224, 242, 422, and their sum is 982. The number 2 counts once even though two copies of the digit 2 are available.

If no even digit is available, no number can be written and the sum is 0.

Input

The first line contains an integer TT (1≤T≤5001 \le T \le 500), the number of test cases.

Each of the next TT lines contains nine integers P1,P2,…,P9P_1, P_2, \dots, P_9 (0≤Pi≤90 \le P_i \le 9), where PiP_i is the number of copies of the digit ii that are available. The odd entries P1,P3,P5,P7,P9P_1, P_3, P_5, P_7, P_9 are part of the input but are never used, because a number may contain even digits only.

Output

For each test case, print one line in the form Case #x: M, where xx is the test case number starting from 1 and MM is the sum of all numbers that can be written, modulo 1,000,000,007.

Examples2

  1. Example 1

    Input
    3
    0 2 0 1 0 0 0 0 0
    0 1 0 0 0 0 0 0 0
    0 1 0 1 0 1 0 1 0
    
    Expected output
    Case #1: 982
    Case #2: 2
    Case #3: 147320
    
  2. Example 2

    Input
    1
    0 0 0 0 0 0 0 0 0
    
    Expected output
    Case #1: 0