CF2200A.Eating Game

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Eating Game

There are nn players playing a game at a circular table. The ii-th player has aia_i dishes to eat. They take turns eating the food, and any player can go first.

During their turn, if player ii has any dishes remaining, they must eat exactly one dish. Then, player (imodn)+1(i \bmod n) + 1 starts their turn. This continues until all dishes are finished.

The player who eats the last dish is considered the winner. Determine the number of players that can possibly be winners.

Input

The first line contains an integer tt (1t50001 \leq t \leq 5000), the number of test cases.

The first line of each test case contains an integer nn (1n101 \leq n \leq 10).

The second line of each test case contains nn integers, the elements of aa (1ai101 \leq a_i \leq 10).

Output

For each test case, output a line with the answer.

Note

In the first test case, player 11 wins for every starting player.

In the second test case, player 22 wins for every starting player.

In the third test case, players 22 and 44 can win.

Samples

3
1
10
2
6 7
4
1 4 3 4
1
1
2

在线编程 IDE

建议全屏模式获得最佳体验