Trump and allegations

All submissions for this problem are available.
As you know America’s Presidential Elections are about to take place and the most popular leader of the Republican party Donald Trump is famous for throwing allegations against anyone he meets.
He goes to a rally and meets n people which he wants to offend. For each person i he can choose an integer between 1 to max[i].
He wants to decide in how many ways he can offend all these persons (N) given the condition that all numbers chosen by him for each person are distinct.
So he needs your help to find out the number of ways in which he can do that. If no solution is possible print 0
Input
The first line of the input contains an integer T (1<=T<=100) denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of people Trump wants to offend. The second line contains N spaceseparated integers maxnumber[0], maxnumber[1], ..., maxnumber[n1] denoting the maxnumber that trump can choose for each person.
Output
For each test case, output a single line containing the number of ways Trump can assign numbers to the people, modulo 1,000,000,007. If it's impossible to assign distinct integers to the people, print 0
Constraints
 1 ≤ T ≤ 100
 1 ≤ N ≤ 50
 1 ≤ Maxnumber[i] ≤ 3000
Example
Input: 3 1 4 2 10 5 4 2 3 1 3 Output: 4 45 0
Explanation
In case 1, He can choose any number from 1 to 4
In case 2,Out of the total 50 combination he can not take (1,1) ,(2,2) , (3,3) ,(4,4) or (5,5).
Author:  shubhamgarg1 
Tags  shubhamgarg1 
Date Added:  17022016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions