Under construction

Still being built. Things may change

Make Numbers with Division

Time limit1sMemory limit1024 MB

Summary
Given how many copies of each number 1 to 9 are available, count the distinct values reachable with division and parentheses, modulo 998244353.
Level

Hard9 of 10

Topics
Math, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

Sebin has several nonzero numbers.

Sebin lays out all of these numbers in a row without concatenating them, and writes one division sign between each pair of adjacent numbers. Then he adds parentheses as many times as he likes to form a valid expression, evaluates it, and tries to make a number.

Suppose Sebin has 1, 2, 3, 4, and 6. Sebin can make the following numbers.

  • (6÷(4÷1)÷3)÷2=14(6 \div (4 \div 1) \div 3) \div 2 = 14
  • (6÷3)÷(4÷1)÷2=14(6 \div 3) \div (4 \div 1) \div 2 = 14
  • (2÷(3÷4))÷(6÷1)=49(2 \div (3 \div 4)) \div (6 \div 1) = 49
  • (4÷6÷(1÷2))÷3=4(4 \div 6 \div (1 \div 2)) \div 3 = 4
  • 4÷(2÷1÷(6÷3))=44 \div (2 \div 1 \div (6 \div 3)) = 4

The numbers that can be made this way are 1144, 136, 116, 19, 14, 49, 1, 94, 4, 9, 16, 36, and 144. That is 13 numbers in total.

Sebin has AiA_i copies of the number ii. Sebin wants to count how many numbers he can make. The number of ways to arrange the numbers and the number of ways to place parentheses both grow very quickly as the count increases, so Sebin needs help counting the numbers he can make.

Input

The first line contains the number of test cases TT. (1≤T≤1051 \le T \le 10^5)

Each test case is given on one line with 9 integers AiA_i separated by spaces. (0≤Ai≤1090 \le A_i \le 10^9, 1≤∑Ai1 \le \sum A_i)

Output

For each test case, print on one line the number of numbers that can be made, modulo 998 244 353.

Examples1

  1. Example 1

    Input
    1
    1 1 1 1 0 1 0 0 0
    
    Expected output
    13