There are N buckets. The task is to assign a certain number of balls to each bucket. Each bucket should have atleast one ball. The capacity of each bucket is provided in an array MAX. For the ith bucket, the capacity is MAX[i] and the number of balls to be assigned to the ith bucket is between 1 to MAX[i] both bounds inclusive. All buckets should have distinct number of balls. Output "the number of ways in which the N buckets can be filled" modulo 10^{9}+7.

**Input:**

First line of the input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case consists of an integer - N denoting the number of buckets. Second line of each test case consists of N space separated integers of array MAX[] denoting the maximum cappacity of each bucket.

**Output:**

For each test case, output the required answer in a separate line.

**Constraints:**

1 ≤ T ≤ 20

1 ≤ N ≤ 1000

1 ≤ MAX[k] ≤ 1000 for k=1,2..N

**Example:**

**Input**

2

1

6

2

5 8

**Output**

6

35

**Explanation**

For the first example, the single bucket can be assigned any number between 1 and 6, inclusive, hence 6 ways.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

thanuvinu94 | 238 |

the_coder95 | 215 |

ShivayLamba | 208 |

sandeep.prajapati | 129 |

Ashish Kumar Vaishy | 114 |

the_coder95 | 1441 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 914 |

tathagat289 | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.