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.

VivSisMMM | 164 |

d_Coder00 | 163 |

ajayjadhav35 | 153 |

Astikeysingh | 148 |

Sathvik Avasarala | 143 |

Pulkit__Sharma__ | 658 |

Anirban166 | 565 |

abducodes | 542 |

Sathvik Avasarala | 506 |

Found_me | 494 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.