Recently, Noakhali became a sovereign state. As a result, the first parliamentary election of the Republic of Noakhali is going to be held soon.
Sajid is a polling officer at an election center. There will be exactly queues of voters and Sajid knows exactly how many voters will be in each queue. At a time, only one person from the front of a non-empty queue will come and give their votes. After that, they will be headed home. The order of persons in each queue is known beforehand. As it’s the first election of their newborn nation, Sajid wants to know every possible situation and be prepared for them. As part of that, he wants to know in how many ways voters can give their votes.
Two ways are said to be different if the sequence of voters giving votes is different.
First line of input will contain an integer (), the number of test cases.
Next lines will describe the test cases.
First line of each test case will contain an integer , the number of queues.
Second line of each test case will contain space separated integers , where is the number of voters in -th queue.
The sum of over all test cases does not exceed .
The sum of the voters of the queues of a single test case does not exceed .
For each test cases, print the answer on a separate line.
As the answer can be really big, print it modulo .
Input | Output |
---|---|
1 2 2 1 | 3 |
There are ways to take the votes described below, The first vote from the first queue, the second vote from the first queue and the third vote from the second queue. The first vote from the first queue, the second vote from the second queue and the third vote from the first queue. The first vote from the second queue, the second vote from the first queue and the third vote from the first queue. |