Goku and Dragon Balls
Difficulty: Hard

Goku was finally successful in collecting all the Dragon Balls (total n of them), each having a unique color. Now for becoming super-powerful, he has to put the Dragon Balls in the holy temple, such that each ball is placed in the room which does NOT have the same color as that particular Dragon Ball. The temple, also has n unique rooms, each having same colors as the Dragon Balls which Goku collected.
<br>He is wondering how many possible ways there are to place the balls in such a manner. Since Goku is tired after collecting all the Dragon Balls, help him calculate the number of ways. As he is tired, he cannot comprehend large numbers, so tell him the answer modulo (10^9 + 7).

###Input:
First line will contain a single integer T, which denotes the number of test cases. The T test cases will then follow. Each test case contains a single integer n, which denotes the number of Dragon Balls that Goku collected as well as the number of rooms in the temple.
<br>0 < T <= 10^6
<br>0 <= n <= 10^7

###Output:
For each test case, print number of ways to place the Dragon Balls such that each one is placed in the room that does NOT have same color as itself (print the answer modulo 10^9 + 7). 

###Sample Input:
2
<br>2
<br>1

###Sample Output:
1
<br>0

###Explanation:
For the first case, assume the two colors are R and B. There is exactly one way to do , place R in B colored room and vice versa.
<br>For the second case, there is no way Goku can satisfy the condition. No superpower for Goku. :(

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
    #include <cstdio>
    #define mod 1000000007
    using namespace std;
    long long int arr[10000008];

    int main ()
    {
        arr[0] = 1;
        arr[1] = 0;
        for (int i = 2; i <= 10000000; i++)
            arr[i] = ( (i-1) * (( arr[i-1] + arr[i-2] ) % mod) ) % mod;
        int cases, n;
        scanf("%d", &cases);
        while(cases--)
        {
            scanf("%d", &n);
            printf("%lld\n", arr[n]);
        }
        return 0;
    }