A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). There are $n! = n \cdot (n-1) \cdot (n - 2) \cdot \ldots \cdot 1$ different permutations of length $n$.

Given a permutation $p$ of $n$ numbers, we create an array $a$ consisting of $2n$ numbers, which is equal to $p$ concatenated with its reverse. We then define the beauty of $p$ as the number of inversions in $a$.

The number of inversions in the array $a$ is the number of pairs of indices $i$, $j$ such that $i < j$ and $a_i > a_j$.

For example, for permutation $p = [1, 2]$, $a$ would be $[1, 2, 2, 1]$. The inversions in $a$ are $(2, 4)$ and $(3, 4)$ (assuming 1-based indexing). Hence, the beauty of $p$ is $2$.

Your task is to find the sum of beauties of all $n!$ permutations of size $n$. Print the remainder we get when dividing this value by $1000000\,007$ ($10^9 + 7$).


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.

Each test case has only one line — the integer $n$ ($1 \leq n \leq 10^5$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, print one integer — the sum of beauties of all permutations of size $n$ modulo $1000000\,007$ ($10^9 + 7$).


-----Examples-----

Input
3
1
2
100
Output
0
4
389456655


-----Note-----

For the first test case of the example, $p = [1]$ is the only permutation. $a = [1, 1]$ has $0$ inversions.

For the second test case of the example, the permutations are $[1, 2]$ and $[2, 1]$. Their respective $a$ arrays are $[1, 2, 2, 1]$ and $[2, 1, 1, 2]$, both of which have $2$ inversions.

Difficulty: EASY
Tags: Combinatorics

Mathematics

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
from sys import stdin, stdout

def sol(a):
	if a == 1:
		return 0
	else:
		c = a * (a - 1)
		for i in range(1, a + 1):
			c = c * i % (10 ** 9 + 7)
		return c
n = int(stdin.readline())
for i in range(n):
	a = int(stdin.readline())
	print(sol(a))


from sys import stdin, stdout
from math import gcd
input = stdin.readline

def fact_mod(n):
	prod = n * (n - 1) % (1000000000.0 + 7)
	while n > 1:
		prod = prod * n % (1000000000.0 + 7)
		n -= 1
	return prod
for _ in range(int(input())):
	n = int(input())
	print(int(fact_mod(n)))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	N = int(input())
	ans = N * (N - 1)
	for i in range(1, N + 1):
		ans *= i
		ans %= 1000000007
	print(ans)


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def print_min(miner):
	if miner == 9999999999999999:
		print(-1, end=' ')
	else:
		print(miner, end=' ')
for _ in range(inp()):
	n = inp()
	mod = 1000000007
	kans = n ** 2 - n
	for i in range(1, n + 1):
		kans = kans * i % mod
	print(kans)


def fact(n):
	f = 1
	for i in range(2, n + 1):
		f = f * i % 1000000007
	return f
t = int(input())
for i in range(t):
	n = int(input())
	res = fact(n) * n * (n - 1) % 1000000007
	print(res)


M = 10 ** 9 + 7
f = [1]
for i in range(1, 7 ** 6):
	f += (f[-1] * i % M,)
for n in [*map(int, open(0))][1:]:
	print(n * (n - 1) * f[n] % M)


def Emordnilap(n):
	factN = moduloFactorial(n)
	b = n * (n - 1) % (10 ** 9 + 7)
	return factN * b % (10 ** 9 + 7)

def moduloFactorial(n):
	mem = [0 for i in range(n + 1)]
	mem[0] = 1
	for i in range(1, n + 1):
		mem[i] = i * mem[i - 1] % (10 ** 9 + 7)
	return mem[n]
t = int(input())
output = []
for i in range(t):
	n = int(input())
	output.append(Emordnilap(n))
for answer in output:
	print(answer)


t = int(input())
mod = int(1000000000.0 + 7)

def solve():
	n = int(input())
	ans = n
	for i in range(1, n + 1):
		ans = ans * i % mod
	ans = ans * (n - 1) % mod
	print(ans)
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
f = [0] * 100001
f[0] = 1
for i in range(1, 100001):
	f[i] = f[i - 1] * i
	f[i] %= 10 ** 9 + 7

def ans(n):
	return f[n] * n * (n - 1) % (10 ** 9 + 7)
for t in range(int(input())):
	n = int(input())
	print(ans(n))


n = int(input())
a = [0 for i in range(n)]
for i in range(n):
	k = int(input())
	fac = 1
	for j in range(2, k + 1):
		fac = j * fac % 1000000007
	sig = 0
	a[i] = fac * k * (k - 1) % 1000000007
for i in range(n):
	print(a[i])


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		temp = n * (n - 1)
		for i in range(1, n + 1):
			temp = temp * i % 1000000007
		print(temp)
main()


t = int(input())
for itr in range(t):
	n = int(input())
	MOD = 1000000007
	ans = 1
	for i in range(2, n + 1):
		ans *= i
		ans %= MOD
	ans *= n * (n - 1)
	ans %= MOD
	print(ans)


import heapq
from collections import *
import math

def factorial(n):
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i
		fact %= 1000000007
	return fact

def solve():
	n = int(input())
	if n == 1:
		print(0)
		return
	ans = 0
	t = factorial(n)
	ans = t % 1000000007 * (n % 1000000007) * ((n - 1) % 1000000007) % 1000000007
	print(ans % 1000000007)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	res = n * (n - 1)
	for i in range(1, n + 1):
		res = res * i % 1000000007
	print(res)


def solve():
	n = int(input())
	if n == 1:
		print('0')
		return
	else:
		m = int(1000000000.0 + 7)
		ans = n * (n - 1)
		for i in range(1, n + 1):
			ans = ans * i % m
		print(ans)
t = int(input())
while t:
	t -= 1
	solve()


MOD = 1000000007
for _ in range(int(input())):
	n = int(input())
	index = 1
	count = n * (n - 1)
	while index <= n:
		count = count % MOD * index % MOD
		index += 1
	print(count)


def perm(n):
	res = n * (n - 1)
	for i in range(2, n + 1):
		res *= i
		res %= 1000000007
	return res % 1000000007
t = int(input())
for _ in range(t):
	n = int(input())
	print(perm(n))


t = int(input())
for _ in range(t):
	n = int(input())
	num = n * (n - 1)
	if n == 1:
		print(0)
		continue
	for i in range(1, n + 1):
		num = num * i % (10 ** 9 + 7)
	print(num)


import sys
input = sys.stdin.readline
division = int(1000000000.0 + 7)
dp = [0, 1] + [0 for i in range(10 ** 5 - 1)]
for i in range(2, 100001):
	dp[i] = dp[i - 1] * i % division
T = int(input())
for i in range(T):
	n = int(input())
	print(dp[n] * n * (n - 1) % division)


def solve():
	num_of_elem = int(input())
	if num_of_elem == 1:
		print(0)
		return
	else:
		moderator = 1000000007
		final_result = num_of_elem * (num_of_elem - 1)
		for index in range(1, num_of_elem + 1):
			final_result = final_result * index % moderator
		print(final_result)
test_cases = int(input())
for i in range(test_cases):
	solve()


import math
n = input()
Output = []
maxi = pow(10, 9) + 7
for i in range(int(n)):
	k = int(input())
	o = 1
	if k == 1:
		o = 0
	for i in range(k, 0, -1):
		o = o * i
		o = o % maxi
	o = o * k * (k - 1)
	o = o % maxi
	Output.append(o)
for i in Output:
	print(i)


def mod_factorial(n, m):
	if n < 2:
		return 0
	else:
		res = 1
		for i in range(2, n + 1):
			res = res * i % m
		return res
const = 1000000007
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		p = n * (n - 1)
		print(p * mod_factorial(n, const) % const)


t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	s = n * (n - 1)
	for k in range(1, n + 1):
		s = k * s % mod
	print(s)


import math
for _ in range(int(input())):
	n = int(input())
	answer = n * (n - 1)
	for i in range(1, n + 1):
		answer *= i
		answer %= 1000000007
	print(answer)


t = int(input())
m = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	res = n * n
	res = res % m
	res *= n - 1
	res = res % m
	res *= n - 1
	res = res % m
	for i in range(2, n - 1):
		res *= i
		res = res % m
	print(res)


tc = int(input())
for _ in range(tc):
	n = int(input())
	mod = int(1000000000.0) + 7
	ans = 1
	for i in range(2, n + 1):
		ans = ans * i % mod
	ans = ans * n % mod
	ans = ans * (n - 1) % mod
	print(ans % mod)


MOD = 1000000007
t = int(input())
while t:
	t -= 1
	n = int(input())
	beauty = 1
	for i in range(1, n + 1):
		beauty = beauty * i % MOD
	beauty = beauty * (n - 1) % MOD
	beauty = beauty * n % MOD
	print(beauty)


limit = 1000000007
t = int(input())
for k in range(t):
	n = int(input())
	inversion = n * (n - 1)
	for i in range(2, n + 1):
		inversion = inversion * i % limit
	print(inversion % limit)


for _ in range(int(input())):
	n = int(input())
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % (10 ** 9 + 7)
	for i in [n, n - 1]:
		ans = ans * i % (10 ** 9 + 7)
	print(ans)


def Solve():
	n = int(input())
	if n == 1:
		return 0
	else:
		ans = 10 ** 9 + 7
		res = n * (n - 1)
		for i in range(1, n + 1):
			res = res * i % ans
		return res

def meow():
	t = int(input())
	while t != 0:
		print(Solve())
		t -= 1
meow()


for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		mod = 10 ** 9 + 7
		out = n * (n - 1)
		for i in range(1, n + 1):
			out = out * i % mod
		print(out)


TOMOD = 1000000007
t = int(input())
for _ in range(t):
	n = int(input())
	x = n * (n - 1) % TOMOD
	for i in range(1, n + 1):
		x = x * i % TOMOD
	print(x)


def fact(n):
	p = 1
	for i in range(1, n + 1):
		p = p * i % (10 ** 9 + 7)
	return p
t = int(input())
for i in range(t):
	n = int(input())
	p = fact(n)
	ans = p * (n * (n - 1))
	ans = ans % (10 ** 9 + 7)
	print(ans)


import itertools
kol = int(input())
for j in range(0, kol):
	n = int(input())
	m = 10 ** 9 + 7
	cost = n * (n - 1)
	for i in range(1, n + 1):
		cost = cost * i % m
	res = cost
	print(res)


t = int(input())
mod = int(1000000000.0 + 7)
while t > 0:
	n = int(input())
	if n == 1:
		print(0)
	else:
		summ = n * (n - 1)
		for i in range(1, n + 1):
			summ = summ * i % mod
		print(summ)
	t -= 1


from itertools import permutations

def fact(n):
	ans = 1
	for i in range(1, n + 1):
		ans *= i
	return ans

def inversions(arr):
	inv = 0
	for i in range(0, len(arr)):
		for j in range(i + 1, len(arr)):
			if arr[i] > arr[j]:
				inv += 1
	return inv

def solveB():
	n = int(input())
	ANS = (n - 1) * n
	ANS = ANS % (10 ** 9 + 7)
	for i in range(1, n + 1):
		ANS *= i
		ANS = ANS % (10 ** 9 + 7)
	print(ANS)

def solveA():
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	consecs = 0
	currentPar = arr[0] % 2
	for x in arr[1:]:
		if x % 2 == currentPar:
			consecs += 1
		else:
			currentPar = x % 2
	print(consecs)
t = int(input())
for tc in range(t):
	solveB()


MOD = 1000 * 1000 * 1000 + 7
t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		f = 1
		for j in range(2, n + 1):
			f = f * j % MOD
		k = n - 1
		m = (1 + k) * k
		f = f * m % MOD
		print(f)


def fact(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % 1000000007
	return ans % 1000000007

def solve():
	n = int(input())
	print(n * (n - 1) * fact(n) % 1000000007)
t = int(input())
for i in range(1, t + 1):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		mod = 1000000000.0 + 7
		temp = n * (n - 1)
		for j in range(1, n + 1):
			temp = temp * j % mod
		print(int(temp))


import math
m = 1000000000.0 + 7
tc = int(input())
for i in range(tc):
	num = int(input())
	a = (num - 1) * num
	i = 1
	while i != num + 1:
		a = a % m * i % m
		i += 1
	print(int(a))


t = int(input())
while t > 0:
	n = int(input())
	k = 1
	for i in range(1, n + 1):
		k = k * i % 1000000007
	print(k * n * (n - 1) % 1000000007)
	t -= 1


for _ in range(int(input())):
	a = int(input())
	mod = 1000000007
	b = 1
	ans = a * (a - 1)
	while b <= a:
		ans = ans % mod * b % mod
		b += 1
	print(ans)


mid = 1000000007
for i in range(int(input())):
	n = int(input())
	mi = n * (n - 1)
	for i in range(2, n + 1):
		mi *= i
		mi %= mid
	print(mi)


t = int(input())
x = 1000000007
for i in range(0, t):
	n = int(input())
	ans = 1
	y = 2
	if n == 1:
		print(0)
	elif n == 2:
		ans = 1
		y = 2
		print(4)
	else:
		for j in range(3, n + 1):
			y = y * j % x
		print(y * n * (n - 1) % x)


n = int(input())
modulo = 1000000007

def factorial(alpha, modulo):
	n = 1
	for i in range(alpha):
		n = n * (i + 1) % modulo
	return n
for i in range(n):
	ola = int(input())
	print(ola * (ola - 1) * factorial(ola, modulo) % modulo)


def fac(n):
	ans = 1
	for i in range(2, n + 1):
		ans = ans * i % 1000000007
	return ans % 1000000007
t = int(input())
for i in range(0, t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		print(fac(n) * n * (n - 1) % 1000000007)


import math
fact = [1]
for i in range(1, 10 ** 5 + 1, 1):
	fact.append(i * fact[i - 1] % (10 ** 9 + 7))
t = int(input())
for j in range(t):
	n = int(input())
	answer = n * (n - 1) * fact[n]
	answer = answer % (10 ** 9 + 7)
	print(answer)


for i in range(int(input())):
	k = int(input())
	ans = k * (k - 1)
	for kj in range(2, k + 1):
		ans = ans * kj % 1000000007
	print(ans)


MOD = 1000000007
t = int(input())
for t in range(t):
	n = int(input())
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i % MOD
	ans = n % MOD * (n - 1) % MOD % MOD * (fact % MOD) % MOD
	print(ans)


def factorial(x):
	res = 1
	for i in range(2, x + 1):
		res = res * i % m
	return res
m = 1000000007
for _ in range(int(input())):
	n = int(input())
	print(factorial(n) % m * n % m * (n - 1) % m % m)


for _ in range(int(input())):
	n = int(input())
	ans = n
	for i in range(n):
		ans = ans * (i + 1) % 1000000007
	ans = ans * (n - 1) % 1000000007
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	m = 1
	for i in range(1, n + 1):
		m = m * i % 1000000007
	print(n * (n - 1) % 1000000007 * m % 1000000007)


for i in range(int(input())):
	n = int(input())
	summ = n * (n - 1)
	for i in range(1, n + 1):
		summ = summ * i % (1000000000.0 + 7)
	print(int(summ))


for _ in range(int(input())):
	n = int(input())
	f = 1
	m = int(1000000000.0 + 7)
	for i in range(n):
		f *= i + 1
		f %= m
	res = n * (n - 1) * f
	res %= m
	print(res)


test_cases = int(input())
while test_cases > 0:
	test_cases -= 1
	n = int(input())
	mod = 1000000007
	ans = 0
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i % mod
	ans = fact * (n * (n - 1) // 2) % mod * 2 % mod
	print(ans)


def problem_b(n):
	mod_num = 1000000007
	total = 0
	temp = 2
	for i in range(n - 1):
		total += temp
		temp += 2
	factorial = 1
	for i in range(1, n + 1):
		factorial *= i
		factorial %= mod_num
	return total * factorial % mod_num
n_problems = int(input().strip())
for i in range(n_problems):
	n = int(input().strip())
	r = problem_b(n)
	print(r)


modd = 1000000007
for _ in range(int(input())):
	summ = 1
	n = int(input())
	s1 = n * (n - 1) % modd
	for i in range(1, n + 1):
		summ = summ * i % modd
	print(summ * s1 % modd)


import math

def nb_inversion(size):
	mod = 1000000007
	nf = 1
	for i in range(size):
		nf = nf * (i + 1)
		nf = nf % mod
	ans = nf * size * (size - 1)
	ans = ans % mod
	print(ans)
nb_case = int(input())
for i in range(nb_case):
	arr_size = int(input())
	nb_inversion(arr_size)


MOD = 1000000007

def main():
	i = int(input())
	for _ in range(i):
		n = int(input().strip('\r\n'))
		res = n * (n - 1)
		for i in range(2, n + 1):
			res *= i
			res = res % MOD
		print(res)
main()


m = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	sol = n * (n - 1)
	i = 1
	while i != n + 1:
		sol = sol % m * i % m
		i += 1
	print(sol)


t = int(input())
while t > 0:
	n = int(input())
	res = int((n - 1) * n)
	m = int(1000000000.0 + 7)
	j = int(1)
	while j != n + 1:
		res = res % m * j % m
		j += 1
	print(res)
	t -= 1


n = int(input(''))
for i in range(n):
	a = int(input(''))
	ans = a * (a - 1)
	if a == 1:
		print(0)
	else:
		for i in range(1, a + 1):
			ans *= i
			ans %= 1000000007
		print(ans)


from math import *
for z in range(int(input())):
	n = int(input())
	mod = 10 ** 9 + 7
	ans = n * (n - 1)
	for i in range(2, n + 1):
		ans = ans * i % mod
	print(ans)


mod = 1000000007
fac = [1]
for i in range(1, 100001):
	fac.append(fac[i - 1] % mod * i % mod)
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		ans = fac[n] % mod * (n * (n - 1) % mod) % mod
		print(ans)


mod = 1000000007

def fac(n):
	fact = 1
	for i in range(2, n + 1):
		fact = fact * i % mod
	return fact
t = int(input())
for _ in range(t):
	n = int(input())
	l = [0]
	for i in range(2, n + 1):
		l.append(l[-1] + 2 * (i - 1))
	print(l[-1] * fac(n) % mod)


for _ in range(int(input())):
	n = int(input())
	m = 1
	p = 10 ** 9 + 7
	for i in range(n):
		m *= i + 1
		m %= p
	m *= n * (n - 1)
	print(m % p)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	res = 1
	for i in range(1, n + 1):
		res *= i
		res = res % (10 ** 9 + 7)
	res = res * n * (n - 1)
	res = res % (10 ** 9 + 7)
	print(res)


m = int(input())
MOD = 10 ** 9 + 7
for k in range(m):
	n = int(input())
	ans = 1
	for i in range(1, n + 1):
		ans = i * ans % MOD
	ans = ans * n * (n - 1) % MOD
	print(ans)


f = [0] * 100001
f[0] = 1
for i in range(1, 100001):
	f[i] = f[i - 1] * i
	f[i] %= 10 ** 9 + 7

def ans(n):
	return f[n] * n * (n - 1) % (10 ** 9 + 7)
for t in range(int(input())):
	n = int(input())
	print(ans(n))


l = [1]
for i in range(1, 10 ** 5 + 1):
	l.append(i * l[-1] % (10 ** 9 + 7))
for _ in range(int(input())):
	a = int(input())
	print(a * (a - 1) * l[a] % (10 ** 9 + 7))


for _ in range(int(input())):
	b = int(input())
	cons = 10 ** 9 + 7
	t = 1
	for i in range(b):
		t = t * (i + 1) % cons
	t = t * b * (b - 1) % cons
	print(t)


t = int(input())
fact = [1]
M = 1000000007
for i in range(1, 100005):
	fact.append(fact[-1] * i % M)
for i in range(t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		x = fact[n] * n % M * (n - 1) % M
		print(x)


def fac(n, mod):
	f = 1
	for i in range(1, n + 1):
		f = f * i % mod
	return f
for dslk in range(int(input())):
	n = int(input())
	ans = n * (n - 1)
	ans *= fac(n, 1000000007)
	ans %= 1000000007
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	k = (n - 1) * n
	p = 1
	for j in range(1, n + 1):
		p = p * j
		p = p % 1000000007
	print(k * p % 1000000007)


def read():
	return int(input())

def read_list():
	return [int(x) for x in input().split(' ')]
test_count = read()
big_mod = 1000000007
for ts in range(test_count):
	n = read()
	x = n - 1
	r = x * (x + 1) // 2
	r *= 2
	fact = 1
	for i in range(1, n + 1):
		r = r * i % big_mod
	print(r)


fac = [1]

def build():
	i = 1
	while i <= 100000:
		fac.append(fac[len(fac) - 1] * i % 1000000007)
		i += 1

def sol():
	p = int(input())
	inv = p * (p - 1)
	print(inv * fac[p] % 1000000007)
build()
t = int(input())
for i in range(t):
	sol()


def fact(x):
	l = x * (x - 1)
	for i in range(1, x + 1):
		l = l * i
		l = l % (10 ** 9 + 7)
	return l
tc = int(input())
for _ in range(tc):
	n = int(input())
	l = fact(n)
	print(l)


def solve():
	n = int(input())
	if n == 1:
		print(0)
		return
	else:
		mod = int(1000000000.0 + 7)
		out = n * (n - 1)
		for i in range(1, n + 1):
			out = out * i % mod
		print(out)
t = int(input())
while t:
	solve()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	out = n * (n - 1)
	mod = 1000000000.0 + 7
	for i in range(1, n + 1):
		out = i * out % mod
	print(int(out))


def factmod(x):
	f = 1
	for i in range(2, x + 1):
		f *= i
		f %= 1000000007
	return f

def invm(x):
	inv = 0
	for i in range(2, x + 1):
		inv += i - 1
		inv %= 1000000007
	return 2 * inv

def taskB():
	n = int(input())
	if n == 1:
		print(0)
		return
	f = factmod(n)
	inv = invm(n)
	res = f * inv % 1000000007
	print(int(res))
t = int(input())
for i in range(t):
	taskB()


for _ in range(int(input())):
	k = int(input())
	l = (k - 1) * k
	c = 1
	h = 1000000007
	while c != k + 1:
		l = l % h * c % h
		c += 1
	print(l)


momos = 1000000000.0 + 7
for _ in range(int(input())):
	n12 = int(input())
	ananas = (n12 - 1) * n12
	ii = 1
	while ii != n12 + 1:
		ananas = ananas % momos * ii % momos
		ii += 1
	print(int(ananas))


t = int(input())
for o in range(t):
	thank = int(input())
	mod = 1000000000.0 + 7
	op = 1
	count = thank * (thank - 1)
	while op != thank + 1:
		count = count % mod * op % mod
		op = op + 1
	print(int(count))


M = 10 ** 9 + 7

def f(n):
	m = 1
	for i in range(1, n + 1):
		m *= i
		if m >= M:
			m %= M
	return m
for _ in range(int(input())):
	n = int(input())
	r = n * (n - 1) * f(n)
	print(r % M)


mod = 1000000007
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		r = 1
		for i in range(1, n + 1):
			r = r * i % mod
		r = r * (n - 1) % mod
		r = r * n % mod
		print(r)


t = int(input())
for i in range(0, t):
	n = int(input())
	f = 1
	for i in range(1, n + 1):
		f = f * i % (10 ** 9 + 7)
	it = n * (n - 1)
	ans = f * it
	mod = 10 ** 9 + 7
	print(ans % mod)


t = int(input())
while t > 0:
	n = int(input())
	if n == 1:
		print(0)
	else:
		mod = 1000000007
		out = n * (n - 1)
		for i in range(1, n + 1):
			out = out * i % mod
		print(out)
	t -= 1


for i in range(int(input())):
	n = int(input())
	ans = n * (n - 1)
	div = 1000000007
	for i in range(1, n + 1):
		ans = ans * i % div
	print(ans)