L. Good Transformations
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Rami has started to learn $$$2$$$ dimensional discrete geometry.

Given an infinite grid $$$G$$$, he will apply a linear transformation $$$T$$$ to each point $$$(i,j)$$$.

A linear transformation $$$T$$$ is a function that sends $$$(i,j)\rightarrow (i',j')$$$ with: $$$$$$ \begin{cases} i'=ai+bj\\ j'=ci+dj \end{cases} $$$$$$ With $$$a,b,c,d\in\mathbb{Z}$$$ its parameters which do not depend on $$$(i,j).$$$

Also he divided the grid into square blocks each with dimensions $$$m\times m$$$, with the $$$(i,j)^\text{th}$$$ block defined as: $$$$$$ B_{i,j}\quad \text{is the set}\quad \left\{ (i\cdot m+u,j\cdot m+v),\quad u,v\in\{0,\dots,m-1\}\right\} $$$$$$ Furthermore, he defined the $$$(u,v)^\text{th}$$$ point of a block $$$B_{i,j}$$$ as the point $$$(i\cdot m+u,j\cdot m+v)$$$

The $$$m$$$-score $$$\chi_m(T)$$$ of a linear transformation $$$T$$$ is defined as the number of pairs $$$(u,v)$$$ such that:

  1. $$$u,v\in\{0,\dots,m-1\}$$$
  2. There exists integers $$$i,j,p,q\in\mathbb{Z}$$$ such that $$$T(p,q)$$$ is the $$$(u,v)^\text{th}$$$ point of the block $$$B_{i,j}$$$

Now, Rami is interested on a family of linear transformations that he called $$$m$$$-good transformations.

In fact, an $$$m$$$-good transformation is defined as a linear transformation $$$T$$$ that:

  • Maximizes $$$\chi_m(T)$$$ over all linear transformations.
  • Has as parameters $$$0\le a,b,c,d \lt m.$$$

Rami wants to count the number of $$$m$$$-good transformations for a given $$$m$$$ modulo $$$M=10^9+7$$$.

Please help him.

Input
  • $$$1\le T \le 10^6$$$ the number of test cases.
  • Each test case consists of a single line containing a single integer $$$1\le m \le 10^6$$$
Output

For each test case, output the number of $$$m$$$-good transformations modulo $$$M=10^9+7$$$

Example
Input
5
2
3
10
25
100
Output
6
48
2880
300000
28800000
Note

This is a visualisation of a linear transformation $$$T$$$ for $$$m=2.$$$ Each block has its own colour. Also the points generated by this linear transformation are shown.

It can be proven that this transformation is $$$m$$$-good.

This is another visualisation of a linear transformation $$$T$$$ for $$$m=3.$$$

It can be proven that there exists a linear transformation $$$S$$$ with $$$\chi_3(S) \gt 3.$$$ And so this linear transformation is not $$$m$$$-good.