#P7742. [2019年杭电多校]Rikka with Mista

[2019年杭电多校]Rikka with Mista

Rikka with Mista

Problem Description

Rikka is a fervent fan of JoJo's Bizarre Adventure. As the last episode of Golden Wind has been aired, Rikka, with the help of Yuta, sets up this problem to express the love to Mista. Mista's lucky number is 44. Today, Mista wants to test his luck with nn magic cards: For each card, there is a non-negative integer on each side. The two numbers on the iith card are wiw_i and 00. Firstly, Mista puts these nn cards to table one by one. For each card, the probability of the wiw_i side to be upward is 12\frac{1}{2}, and these probabilities are independent with each other. As a result, there are nn integers on the table. Mista then sums up all these integers and counts the number of 44s in the decimal representation of this sum: He uses this result to measure his luckiness. Since it's possible for each side of each card to be upward, there are 2n2^n possible states in total. You are required to calculate the sum of the results for all these situations.

Input

The first line of the input contains a single integer T(4T4)T(4 \leq T \leq 4), the number of test cases. For each test case, the first line contains a single integer n(4n40)n(4 \leq n \leq 40), the number of the cards. The second line contains nn integers w1,,wn(4wi44444444)w_1, \dots, w_n(4 \leq w_i \leq 44444444), the positive numbers on the cards.

Output

For each test case, output a single line with a single integer, the answer. Hint There are 4444 44s in the sample input. Mista would like this sample input. In the first test case, there is 11 state with the sum equal to 00; 44 states with the sum equal to 44; 66 states with the sum equal to 88; 44 states with the sum equal to 1212 and 11 state with the sum equal to 1616. Therefore, there are only 44 situations with the result equal to 11 while on other cases, the result is 00. So the answer should be 44.

Sample Input

4

4

4 4 4 4

4

4 4 44 44

4

4 44 44 4444

4

444 44444 44444 4444444

Sample Output

4

10

24

38

Source

2019 Multi-University Training Contest 9