eolymp
bolt
Try our new interface for solving problems
Problems

Algebraic Teamwork

Algebraic Teamwork

The great pioneers of group theory and linear algebra want to cooperate and join their theories. In group theory, permutations – also known as bijective functions – play an important role. For a finite set A, a function σ : AA is called a permutation of A if and only if there is some function ρ : AA with

σ(ρ(a)) = a and ρ(σ(a)) = a for all a from A

The other half of the new team - the experts on linear algebra - deal a lot with idempotent functions. They appear as projections when computing shadows in 3D games or as closure operators like the transitive closure, just to name a few examples. A function p : AA is called idempotent if and only if

ρ(ρ(a)) = ρ(a) for all a from A

To continue with their joined research, they need your help. The team is interested in non-idempotent permutations of a given finite set A. As a first step, they discovered that the result only depends on the set's size. For a concrete size n (1n105), they want you to compute the number of permutations on a set of cardinality n that are not idempotent.

Input

Starts with the number t (t100) of test cases. Then t lines follow, each containing the set's size n (1n105).

Output

Output one line for every test case containing the number modulo 1 000 000 007 = (109 + 7) of non-idempotent permutations on a set of cardinality n.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3
1
2
2171
Output example #1
0
1
6425
Source 2014 German Collegiate Programming Contest (GCPC), May 24, Problem A