Strongly Connected Digraphs
Difficulty: Hard

Count the number of [labeled strongly connected digraphs](http://en.wikipedia.org/wiki/Directed_graph) with the given number of vertices.  

**Input Format**  
The first line contains $T$, the number of queries.  
Following are $T$ lines. Each line contains one integer $N$, denoting the number of vertices.  

**Output Format**  
Output $T$ lines. Each line is the number of labeled strongly connected digraphs with $N$ vertices, modulo $(10^9 + 7)$. 

**Constraints**  
$1 \le T \le 1000$  
$1 \le N \le 1000$  

**Sample Input**

	5
	1
	2
	3
	4
	1000

**Sample Output**

	1
	1
    18
    1606
    871606913

**Explanation**

You can refer to [oeis](http://oeis.org/A003030).


Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (Python):
###Python 2  
```python  
'''
Use the ff:
http://www.emis.de/journals/AUSM/C5-1/math51-5.pdf
http://people.brandeis.edu/~gessel/homepage/students/ostroffthesis.pdf
(Beware, they both have mistakes!)
'''

mod = 10**9+7
MAX = 1001

C = [[0]*MAX for i in xrange(MAX)]
e = [0]*MAX
s = [0]*MAX
for n in xrange(MAX):
    for r in xrange(n+1):
        C[n][r] = 1 if r == 0 or r == n else (C[n-1][r-1] + C[n-1][r]) % mod
    e[n] = (pow(2, n*(n-1), mod) - sum(C[n][i]*pow(2, (n-1)*(n-i), mod)*e[i] for i in xrange(1,n))) % mod
    s[n] = (e[n] + sum(C[n-1][i-1]*s[i]*e[n-i] for i in xrange(1,n))) % mod

for cas in xrange(input()):
    print s[input()]
```