Expectations on a Permutation

 A permutation of length 

N is an array of N integers A1,A2,,AN such that every integer from 1 to N appears in it exactly once.

We define a function over a permutation as follows: F(A)=(A1A2)+(A2A3)++(AN2AN1)+(AN1AN)

You are given an integer N. What is the expected value of the function F over all possible permutations of length N?

The expected value of the function can be represented as a fraction of the form PQ. You are required to print PQ1(mod1000000007).

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains a single integer N.

Output Format

For each test case, output on a single line the expected value of the function modulo 1000000007.

Constraints

  • 1T105
  • 2N109

Sample Input 1 

2
2
3

Sample Output 1

2
333333343

Explanation

  • Test Case 1: There are 2 possible permutations: A={1,2} with F(A)=2 and A={2,1} with F(A)=2. Hence the expected value of the function is F(A)=122+122=2.

  • Test Case 2: There are 6 possible permutations, with the value of function as {5,5,8,8,9,9}. Hence the expected value of the function is F(A)=5+5+8+8+9+96=223.

Previous
Next Post »