Algebraic Teamwork#7695

Algebraic Teamwork

1 second
128 megabytes
Medium

The great pioneers of group theory and linear algebra want to cooperate and combine their theories. In group theory, permutations (also known as bijective functions) play an important role. For a finite set , a function \sigma : A \rightarrow A is called a permutation of if and only if there exists a function \rho : A \rightarrow A such that

\sigma(\rho(a)) = a \text{ and } \rho(\sigma(a)) = a \text{ for all } a \in A

The other half of the new team—the experts in linear algebra—work with idempotent functions. Such functions appear, for example, as projections when computing shadows in 3D games or as closure operators like the transitive closure. A function p : A \rightarrow A is called idempotent if and only if

p(p(a)) = p(a) \text{ for all } a \in A

To continue their joint research, they need your help. The team is interested in non-idempotent permutations of a given finite set . As a first step, they discovered that the result depends only on the size of the set. For a given size (1 \leq n \leq 10^5), they want you to compute the number of permutations on a set of cardinality that are not idempotent.

\InputFileThe input starts with the integer (1 \leq t \leq 100), the number of test cases. Then lines follow, each containing an integer (1 \leq n \leq 10^5) — the size of the set.

\OutputFileFor each test case, output the number of non-idempotent permutations on a set of cardinality , modulo = 10^9 + 7.

Examples

Example 1

Loading
Loading