Server Time: Sun Sep 27, 2020 4:20 pm
 Welcome ( logout )
B - One Unit Machine
 PDF (English) Ranklist
 Time Limit: 2 second(s) Memory Limit: 32 MB

OUM is a one unit machine which processes jobs. Since it can't handle heavyweight jobs; jobs needs to be partitioned into units. Initially, all the job information and unit partitions are given as input. Then the machine allocates necessary time slots. And in each time slot it asks the user for the name of the job to be processed. After getting the name; the machine determines the next unprocessed unit of that job and processes that unit in that slot. If there is no such unit, the machine crashes. A job is said to be complete if all the units of that job are complete.

For example, let J1 and J2 be two jobs each having 2 units. So, OUM will create 4 time slots. Now the user can give J1 J2 J2 J1 as input. That means it completes the 1st unit of J1 in time slot 1 and then completes the 1st unit of J2 in time slot 2. After that it completes the 2nd unit of J2 and 2nd unit of J1 in time slots 3 and 4 respectively. But if the user gives J1 J1 J2 J1 as input, the machine crashes in time slot 4 since it tries to process 3rd unit of J1 which is not available.

Now, Sam is the owner of a software firm named ACM and he has n jobs to complete using OUM. He wants to complete Jobi before Jobi+1 where 1 ≤ i < n. Now he wants to know the total number of ways he can complete these jobs without crashing the OUM. He assigned you for this task. Two ways are different if at tth slot one processed a unit of Jobi and another processed a unit of Jobj where i ≠ j. For the example above, there are three ways:

J1 J1 J2 J2

J1 J2 J1 J2

J2 J1 J1 J2

# Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with an integer n (1 ≤ n ≤ 1000). The next line contains n space separated positive integers k1, k2, k3 ... kn. Where, ki denotes the number of units for the ith job. You can assume that total number of units for all the jobs in any case is not greater than 106.

# Output

For each case, print the case number and the result modulo 1000,000,007.

# Output for Sample Input

2

2

2 2

3

2 2 3

Case 1: 3

Case 2: 45

Problem Setter: Kazi Rakibul Hossain
Special Thanks: Jane Alam Jan
 Developed and Maintained by JANE ALAM JAN Copyright © 2012 LightOJ, Jane Alam Jan