Chef is solving mathematics problems. He is preparing for Engineering Entrance exam. He's stuck in a problem.
$f(n)=1^n*2^{n-1}*3^{n-2} * \ldots * n^{1} $ 
Help Chef to find the value of $f(n)$.Since this number could be very large, compute it modulo $1000000007$.

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow. 
- Each testcase contains of a single line of input,  $N$. 

-----Output:-----
For each testcase, output in a single line the value of $f(n)$ mod $1000000007$.

-----Constraints-----
- $1 \leq T \leq 10^6$
- $1 \leq N \leq 10^6$

-----Subtasks-----
Subtask 1(24 points) : 
- $1 \leq T \leq 5000$
- $1 \leq N \leq 5000$
Subtask 2(51 points) : original constraints

-----Sample Input:-----
1
3

-----Sample Output:-----
12

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Mathematics


Solutions:
def fun(n):
	a = []
	x = 1
	a.append(x)
	b = []
	b.append(a[0])
	for i in range(2, n + 1):
		x = x * i % 1000000007
		a.append(x)
		b.append(b[i - 2] * a[i - 1] % 1000000007)
	return b
t = fun(10 ** 6)
for i in range(int(input())):
	n = int(input())
	print(t[n - 1])


MOD = 1000000007

def mathl(n):
	mod_fact = [1]
	fact = 1
	nor_fact = []
	for i in range(1, n + 1):
		fact = fact * i % MOD
		nor_fact.append(fact)
	for i in range(1, len(nor_fact)):
		mod_fact.append(mod_fact[-1] * nor_fact[i] % MOD)
	return mod_fact
res = mathl(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	print(res[n - 1])


m = 1000000007

def jk(n):
	arr = [1]
	cnt = 1
	ans = []
	for i in range(1, n + 1):
		cnt = cnt * i % m
		ans.append(cnt)
	for i in range(1, len(ans)):
		arr.append(arr[-1] * ans[i] % m)
	return arr
t = jk(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	print(t[n - 1])


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
fact = [1] * 1000001
c = 1
for i in range(1, 1000001):
	fact[i] = fact[i - 1] * c % mod
	c += 1
prod = [1] * 1000001
pro = 1
for i in range(1, 1000000 + 1):
	pro = pro % mod * fact[i] % mod
	prod[i] = pro
for _ in range(vary(1)):
	n = vary(1)
	print(prod[n] % mod)


m = 1000000007

def Create(n):
	arr = [1]
	cnt = 1
	ans = []
	for i in range(1, n + 1):
		cnt = cnt * i % m
		ans.append(cnt)
	for i in range(1, len(ans)):
		arr.append(arr[-1] * ans[i] % m)
	return arr
A = Create(1000000)
for _ in range(int(input())):
	n = int(input())
	print(A[n - 1])


arr = [1]
for j in range(1, 1000001):
	arr.append(j * arr[j - 1] % 1000000007)
ans = [1]
for j in range(1, 1000001):
	ans.append(arr[j] * ans[j - 1] % 1000000007)
for i in range(int(input())):
	n = int(input())
	print(ans[n])


m = 10 ** 9 + 7

def func():
	fact = []
	arr = []
	fact.append(1)
	arr.append(0)
	arr.append(1)
	for i in range(1, 10 ** 6 + 1):
		fact.append(fact[i - 1] * i % m)
	for i in range(2, 10 ** 6 + 1):
		arr.append(arr[i - 1] * fact[i] % m)
	return arr
arr = func()
t = int(input())
for i in range(0, t):
	n = int(input())
	print(arr[n])


dit = {1: 1}
f = 1
rem = 1
for i in range(2, 10 ** 6 + 1):
	f = f * i % 1000000007
	rem = rem * f % 1000000007
	dit.setdefault(i, rem)
for i in range(int(input())):
	n = int(input())
	print(dit[n])


import math
dic = dict()
dic[1] = 1
dp = dict()
dp[1] = 1
for i in range(2, 1000000 + 1):
	dic[i] = dic[i - 1] * i % 1000000007
	dp[i] = dp[i - 1] * dic[i] % 1000000007
for _ in range(int(input())):
	n = int(input())
	ans = dp[n]
	print(ans)


from sys import *
input = stdin.readline
l = [0] * (10 ** 6 + 1)
l[1] = 1
p = 1
m = 10 ** 9 + 7
for i in range(2, 10 ** 6 + 1):
	l[i] = l[i - 1] * (p * i) % m % m
	p *= i
	p = p % m
for u in range(int(input())):
	print(l[int(input())])


a = [0] * (10 ** 6 + 1)
mod = 10 ** 9 + 7
a[1] = 1
p = 1
for i in range(2, 10 ** 6 + 1):
	a[i] = a[i - 1] * (p * i % mod) % mod
	p *= i
	p = p % mod
t = int(input())
for i in range(t):
	n = int(input())
	print(str(a[n]))


self = 1
prev = 1
li = [0] * 1000000
for i in range(1, 1000001):
	self = self * i % 1000000007 * prev % 1000000007
	prev = prev * i % 1000000007
	li[i - 1] = self
for case in range(int(input())):
	n = int(input())
	print(li[n - 1])


t = int(input())
N = 10 ** 6
MOD = 10 ** 9 + 7
fact = {}
fact[0] = 1
for i in range(1, N + 1):
	fact[i] = fact[i - 1] * i % MOD
cf = {}
cf[0] = 1
for i in range(1, N + 1):
	cf[i] = fact[i] * cf[i - 1]
	cf[i] = cf[i] % MOD
while t != 0:
	t -= 1
	n = int(input())
	print(cf[n])


li = []
li.append(0)
x = 1
for i in range(1, 1000001):
	if i == 1:
		li.append(i)
	else:
		x = x * i
		x = x % 1000000007
		val = li[i - 1] * x % 1000000007
		li.append(val)
for _ in range(int(input())):
	n = int(input())
	ans = li[n]
	print(ans)


T = int(input())
t = []
for _ in range(T):
	N = int(input())
	t.append(N)
N = max(t) + 1
l = [0 for i in range(N)]
p = 1
a = 1
for i in range(1, N):
	a = a * i % 1000000007
	p = p * a % 1000000007
	l[i] = p
for i in t:
	print(l[i])


t = int(input())
fact = []
new_fact = []
fact.append(1)
fact.append(1)
result = 1
for i in range(2, 10 ** 6 + 1):
	result = result * i % 1000000007
	fact.append(result)
ans = []
ans.append(1)
ans.append(1)
for i in range(2, 10 ** 6 + 1):
	ans.append(fact[i] * ans[i - 1] % 1000000007)
for i in range(t):
	n = int(input())
	print(ans[n])


f = [1] * 1000001
n = 1000000
ans = [1] * 1000001
for i in range(2, n + 1):
	f[i] = i * f[i - 1] % 1000000007
for i in range(2, n + 1):
	ans[i] = f[i] * ans[i - 1] % 1000000007
for _ in range(int(input())):
	n = int(input())
	print(ans[n])


q = 1000000007

def abc(n):
	arr = [1]
	cnt = 1
	ans = []
	for i in range(1, n + 1):
		cnt = cnt * i % q
		ans.append(cnt)
	for i in range(1, len(ans)):
		arr.append(arr[-1] * ans[i] % q)
	return arr
t = abc(10 ** 6)
a = int(input())
for i in range(a):
	n = int(input())
	print(t[n - 1])


mod = 1000000007
fact = [0] * (10 ** 6 + 1)
dp = [0] * (10 ** 6 + 1)
(fact[1], fact[2]) = (1, 2)
(dp[1], dp[2]) = (1, 2)
for i in range(3, 10 ** 6 + 1):
	fact[i] = fact[i - 1] % mod * (i % mod) % mod
for i in range(3, 10 ** 6 + 1):
	dp[i] = dp[i - 1] % mod * (fact[i] % mod) % mod
for _ in range(int(input())):
	n = int(input())
	print(dp[n])


M = 1000000007

def function(n):
	arr = [1]
	cnt = 1
	ans = []
	for i in range(1, n + 1):
		cnt = cnt * i % M
		ans.append(cnt)
	for i in range(1, len(ans)):
		arr.append(arr[-1] * ans[i] % M)
	return arr
t = function(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	print(t[n - 1])


m = 1000000007
f = [1, 2, 6]
a = [1, 2, 12]
for i in range(3, 10 ** 6):
	f.append(f[i - 1] * (i + 1) % m)
	a.append(f[i] * a[i - 1] % m)
for _ in range(int(input())):
	n = int(input())
	print(a[n - 1])


try:
	mod = 10 ** 6 + 1
	arr = [0]
	arr.append(1)
	arr.append(2)
	count = 3
	l = 2
	m = 1000000007
	for i in range(3, mod):
		l = count * l % m
		arr.append(arr[i - 1] * l % m)
		count += 1
		sub = arr[i]
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		print(arr[n])
except:
	pass


arr = [1]
mod = 1000000007
for i in range(1, 1000001):
	arr.append(arr[-1] * i % mod)
ans = [1]
for i in range(1, 1000001):
	ans.append(ans[-1] * arr[i] % mod)
for _ in range(int(input())):
	n = int(input())
	print(ans[n])


md = 1000000007
ar = [1]
rr = [1]
for i in range(1, 1000001):
	ar.append(ar[i - 1] % md * ((i + 1) % md) % md)
	rr.append(rr[i - 1] % md * (ar[i] % md) % md)
t = int(input())
for j in range(1, t + 1):
	n = int(input())
	print(rr[n - 1])


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
M = 10 ** 9 + 7
f = [1] * 1000001
for i in range(2, 1000001):
	f[i] = i * f[i - 1] % M
for i in range(2, 1000001):
	f[i] = f[i] * f[i - 1] % M
for _ in range(inp()):
	n = inp()
	print(f[n])


m = 1000000007

def solve(n):
	p = []
	f = 1
	a = [1]
	for i in range(1, n + 1):
		f = f * i % m
		p.append(f)
	for i in range(1, len(p)):
		a.append(a[-1] * p[i] % m)
	return a
t = solve(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	print(t[n - 1])


try:
	t = int(input())
	n = []
	for i in range(t):
		num = int(input())
		n.append(num)
	fact = [1]
	facti = [1]
	for i in range(1, max(n) + 1):
		fact.append(i * fact[i - 1] % 1000000007)
		facti.append(facti[i - 1] * fact[i] % 1000000007)
	for i in n:
		print(facti[i])
except:
	pass


import math
mod = 10 ** 9 + 7

def abc(n):
	fact = []
	cnt = 1
	for i in range(1, n + 1):
		cnt = cnt * i % mod
		fact.append(cnt)
	a = [1]
	for i in range(1, n):
		a.append(a[i - 1] * fact[i] % mod)
	return a
a = abc(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	print(a[n - 1])


import math
mod = 1000000007

def mod_add(a, b):
	c = a + b
	if c > mod:
		c -= mod
	return c

def mod_multiply(a, b):
	c = a * b
	return c % mod

def factorial_mod(n):
	Fact = [1]
	for i in range(1, n + 1):
		Fact.append(mod_multiply(Fact[i - 1], i))
	return Fact

def ans(n):
	Fact = factorial_mod(n)
	Ans = [1]
	for i in range(1, n + 1):
		Ans.append(mod_multiply(Fact[i], Ans[i - 1]))
	return Ans
Ans = ans(1000000)
for _ in range(int(input())):
	i = int(input())
	print(Ans[i])


m = 1000000007
l = [1]
for i in range(1, 1000001):
	a = l[i - 1] * i
	l.append(a % m)
ans = [1]
for i in range(1, 1000001):
	b = ans[i - 1] * l[i]
	ans.append(b % m)
t = int(input())
for i in range(t):
	n = int(input())
	print(ans[n])


try:
	m = 10 ** 9 + 7

	def jk(n):
		count = 1
		arr = []
		ans = [1]
		for i in range(1, n + 1):
			count = count * i % m
			arr.append(count)
		for i in range(1, len(arr)):
			ans.append(ans[-1] * arr[i] % m)
		return ans
	t = jk(10 ** 6)
	for _ in range(int(input())):
		num = int(input())
		print(t[num - 1])
except:
	pass


fact = [0, 1, 2]
dp = [0, 1, 2]
mod = 1000000007
for i in range(3, 1000001):
	fact.append(fact[i - 1] % mod * (i % mod) % mod)
for i in range(3, 1000001):
	dp.append(dp[i - 1] % mod * (fact[i] % mod) % mod)
t = int(input())
for i in range(t):
	n = int(input())
	print(dp[n] % mod)


m = 10 ** 9 + 7

def do(n):
	arr = [1]
	cnt = 1
	ans = []
	for i in range(1, n + 1):
		cnt = cnt * i % m
		ans.append(cnt)
	for i in range(1, len(ans)):
		arr.append(arr[-1] * ans[i] % m)
	return arr
t = do(10 ** 6)
for _ in range(int(input())):
	n = int(input())
	print(t[n - 1])


m = 10 ** 9 + 7
n = 10 ** 6
h = 1
b = [0] * n
c = [0] * n
for i in range(1, n + 1):
	h = h * i % m
	b[i - 1] = h
h = 1
for i in range(n):
	h = h * b[i] % m
	c[i] = h
for z in range(int(input())):
	print(c[int(input()) - 1])


from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
print = stdout.write
T = int(input())
M = 1000000007
n = 1000005
Array = [1]
f = 1
for j in range(1, n + 1):
	Array.append(f * j * Array[j - 1] % M)
	f = f * j % M
for i in range(T):
	print(str(Array[int(input())]) + '\n')


import math
p = 1000000007
l = []
aa = 1
bb = 1
for i in range(1, 1000001):
	aa = aa * i % p
	bb = bb * aa % p
	l.append(bb % p)
for _ in range(int(input())):
	a = int(input())
	print(l[a - 1] % p)


t = int(input())
n = []
for i in range(t):
	num = int(input())
	n.append(num)
fact = [1]
facti = [1]
for i in range(1, max(n) + 1):
	fact.append(i * fact[i - 1] % 1000000007)
	facti.append(facti[i - 1] * fact[i] % 1000000007)
for i in n:
	print(facti[i])


from math import factorial
from functools import reduce
lst = [1] * (10 ** 6 + 1)
for j in range(1, 10 ** 6 + 1):
	lst[j] = lst[j - 1] * j % (10 ** 9 + 7)
for j in range(1, 10 ** 6 + 1):
	lst[j] = lst[j - 1] * lst[j] % (10 ** 9 + 7)
for i in range(int(input())):
	n = int(input())
	x = lst[n]
	print(x % (10 ** 9 + 7))


import sys
ip = sys.stdin
mod = pow(10, 9) + 7
MAXN = pow(10, 6)
fn = [0] * (MAXN + 1)
mul = [0] * (MAXN + 1)
fn[1] = 1
mul[1] = 1
for i in range(2, MAXN + 1):
	mul[i] = mul[i - 1] * i % mod
	fn[i] = fn[i - 1] * mul[i] % mod
t = int(ip.readline())
for _ in range(t):
	n = int(ip.readline())
	print(fn[n])


T = int(input())
lis = [1]
for i in range(1, 1000001):
	lis.append(i * lis[-1] % 1000000007)
for i in range(1, 1000001):
	lis[i] = lis[i] * lis[i - 1] % 1000000007
for i in range(T):
	N = int(input())
	print(lis[N])


n = 100000
m = 1000000007
a = [0] * n
a[0] = 1
fib = 1
for i in range(2, n - 200):
	fib = fib * i % m
	a[i - 1] = a[i - 2] * fib % m
for _ in range(int(input())):
	n = int(input())
	print(a[n - 1])


res = [0 for i in range(10 ** 6 + 1)]
M = 1000000007
res[1] = 1
res[0] = 1
multi = 1 * 2
for i in range(2, 10 ** 6 + 1):
	res[i] = res[i - 1] * multi % M
	multi *= i + 1
	multi %= M
t = int(input())
while t > 0:
	n = int(input())
	print(res[n])
	t -= 1


t = int(input())
a = [-1] * 1000007
a[0] = 0
a[1] = 1
l = 1
for i in range(2, 1000007):
	l = l * i % 1000000007
	a[i] = a[i - 1] * l % 1000000007
for _ in range(t):
	n = int(input())
	print(a[n] % 1000000007)


a = [0]
p = 1
p1 = 1
m = 1000000007
for i in range(1, 1000001):
	p = p % m * (i % m) % m
	p1 = p1 % m * (p % m) % m
	a.append(p1 % m)
t = int(input())
while t:
	t -= 1
	n = int(input())
	print(a[n])


MOD = 1000000007
arr = []
ch = 1
ans = 1
for i in range(1, 1000001):
	k = i * ch % MOD
	ch = k
	ans = ans * k % MOD
	arr.append(ans)
t = int(input())
while t > 0:
	n = int(input())
	print(arr[n - 1])
	t = t - 1


import math as m
modulo = pow(10, 9) + 7
fac = [0] * 10 ** 6
fac[0] = 1
for i in range(1, 10 ** 6):
	fac[i] = (i + 1) * fac[i - 1] % modulo
for i in range(1, 10 ** 6):
	fac[i] = fac[i - 1] * fac[i] % modulo
t = int(input())
for i in range(t):
	n = int(input())
	print(fac[n - 1])


DA = [1]
c = [1]
mod = 1000000007

def cal():
	for i in range(1, 1000001):
		DA.append(i * DA[i - 1] % mod)
		c.append(c[i - 1] * DA[i] % mod)
cal()
T = int(input())
while T > 0:
	N = int(input())
	print(c[N] % mod)
	T -= 1


M = 1000000007
t = int(input())
dp = [1, 2]
dp2 = [1, 2]
y = 1
summ = 1
for i in range(2, 1000001):
	z = dp[i - 1] * (i + 1) % M
	dp.append(z)
	y = z * dp2[i - 1] % M
	dp2.append(y)
while t:
	t -= 1
	n = int(input())
	print(dp2[n - 1])


l = [0] * (10 ** 6 + 3)
l[0] = 1
for i in range(1, 10 ** 6 + 1):
	l[i] = l[i - 1] * i % (10 ** 9 + 7)
for j in range(1, 10 ** 6 + 1):
	l[j] = l[j] * l[j - 1] % (10 ** 9 + 7)
n = int(input())
for k in range(1, n + 1):
	b = int(input())
	print(l[b])


t = int(input())
mod = 1000000007
limit = 1000001
fact = [1]
for i in range(1, limit):
	fact.append(i * fact[i - 1] % mod)
for i in range(1, limit):
	fact[i] = fact[i] * fact[i - 1] % mod
for i in range(t):
	n = int(input())
	print(fact[n])


fact = [None] * 1000001
ans = [None] * 1000001
fact[0] = 1
fact[1] = 1
ans[0] = 1
ans[1] = 1
for i in range(2, 1000001):
	fact[i] = fact[i - 1] * i % 1000000007
	ans[i] = fact[i] * ans[i - 1] % 1000000007
for _ in range(int(input())):
	n = int(input())
	print(ans[n])


def al(n1):
	dp = []
	p = 1
	dp.append(p)
	a = []
	a.append(dp[0])
	for i in range(2, n1 + 1):
		p = p * i % 1000000007
		dp.append(p)
		a.append(a[i - 2] * dp[i - 1] % 1000000007)
	return a
a2 = al(10 ** 6)
for t in range(int(input())):
	n = int(input())
	print(a2[n - 1])


from sys import stdin, stdout
a = [0] * (10 ** 6 + 1)
mod = 10 ** 9 + 7
a[1] = 1
p = 1
for i in range(2, 10 ** 6 + 1):
	a[i] = a[i - 1] * (p * i % mod) % mod
	p *= i
	p = p % mod
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	stdout.write(str(a[n]))
	stdout.write('\n')


ls = [0]
fac = 1
ans = 1
big = 1000000007
for i in range(1, 1000001):
	fac = fac % big * (i % big) % big
	ans = ans % big * (fac % big) % big
	ls.append(ans % big)
for __ in range(int(input())):
	n = int(input())
	print(ls[n])


t = int(input())
s = []
for i in range(t):
	n = int(input())
	s.append(n)
n = max(s) + 1
l = [0 for x in range(n)]
p = 1
a = 1
for j in range(1, n):
	a = a * j % 1000000007
	p = p * a % 1000000007
	l[j] = p
for k in s:
	print(l[k])


import collections
from operator import itemgetter

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

def li():
	return list(mi())

def ii():
	return int(input())

def msi():
	return input().split()
mod = 1000000007
a = []
a.append(1)

def sol(n):
	temp = 1
	for i in range(1, n + 1):
		a.append(temp % mod * i % mod % mod)
		temp = a[i]
		a[i] = a[i] * (a[i - 1] % mod) % mod
t1 = ii()
sol(1000000)
while t1:
	t1 -= 1
	n = ii()
	print(a[n])


arr = []
x = 1
y = 1
mod = 10 ** 9 + 7
for i in range(1, 10 ** 6 + 1):
	x *= i
	x = x % mod
	y *= x
	y = y % mod
	arr.append(y)
for i in range(int(input())):
	n = int(input())
	print(arr[n - 1])


mod = 1000000007
fact = [1]
for i in range(1, 10 ** 6 + 1):
	fact += [fact[-1] * i % mod]
ser = [1]
for i in range(1, 10 ** 6 + 1):
	ser += [ser[-1] * fact[i] % mod]
for t in range(int(input())):
	n = int(input())
	print(ser[n])


MODI = 1000000007

def mulmod(a, b, mod):
	res = 0
	a = a % mod
	while b > 0:
		if b % 2 == 1:
			res = (res + a) % mod
		a = a * 2 % mod
		b //= 2
	return res % mod

def ft(N):
	if pro[N] != 0:
		return pro[N]
	product = 1
	fact = 1
	MOD = 1000000000.0 + 7
	for i in range(1, N + 1):
		fact = mulmod(fact, i, MOD)
		product = mulmod(product, fact, MOD)
		if not product:
			return 0
	pro[N] = int(product)
	return int(product)
pro = [0 for i in range(1000003)]
fa = [1 for i in range(1000003)]
pro[1] = 1
pro[2] = 2
pro[3] = 12
fa[1] = 1
fa[2] = 2
fa[3] = 6
for i in range(4, 1000003):
	fa[i] = fa[i - 1] * i % MODI
	pro[i] = pro[i - 1] * fa[i] % MODI
for _ in range(int(input())):
	n = int(input())
	print(pro[n])


x = 1
y = 1
result = []
mod = 1000000007
for i in range(1, 10 ** 6 + 1):
	x *= i
	x = x % mod
	y *= x
	y = y % mod
	result.append(y)
for i in range(int(input())):
	n = int(input())
	print(result[n - 1])


mod = 10 ** 9 + 7
e = 10 ** 6 + 1
f = [0] * e
f[0] = f[1] = 1
fact = 1
for i in range(2, e):
	f[i] = i * fact * f[i - 1] % mod
	fact = fact * i % mod
t = int(input())
for _ in range(t):
	n = int(input())
	print(f[n])


m = 10 ** 9 + 7
d = {1: 1}
fact = 1
val = 1
for i in range(2, 10 ** 6 + 1):
	fact = fact * i % m
	val = val * fact % m
	d[i] = val
for _ in range(int(input())):
	n = int(input())
	print(d[n])


t = int(input())
a = [0] * 1000001
a[1] = 1
d = [0] * 1000001
d[1] = 1
for i in range(2, 1000001):
	a[i] = i * a[i - 1] % 1000000007
	d[i] = d[i - 1] * a[i] % 1000000007
while t > 0:
	n = int(input())
	print(d[n])
	t -= 1


li = [1]
totalpow = [1]

def func():
	for i in range(1, 1000001):
		li.append(i * li[i - 1] % 1000000007)
		totalpow.append(totalpow[i - 1] * li[i] % 1000000007)
func()
test = int(input())
for _ in range(0, test):
	n = int(input())
	print(totalpow[n] % 1000000007)


t = int(input())
m = 10 ** 9 + 7
import math
arr = []
arr.append(0)
arr.append(1)
x = 1
for i in range(2, 10 ** 6 + 1):
	x = x * i % m
	arr.append(arr[i - 1] * x % m)
while t:
	n = int(input())
	print(arr[n])
	t = t - 1


t = int(input())
N = 1000000
l = [1]
a = 1
for i in range(1, N + 1):
	l.append(l[i - 1] * i % 1000000007)
f = [1]
for i in range(1, N + 1):
	f.append(l[i] * f[i - 1] % 1000000007)
for ij in range(t):
	n = int(input())
	print(f[n])


m = 10 ** 9 + 7
ar = []
x = 1
ans = 1
for i in range(10 ** 6):
	f = x % m * ((i + 1) % m) % m
	ans = ans % m * (f % m) % m
	ar.append(ans)
	x = f
tc = int(input())
for ii in range(tc):
	n = int(input())
	ans = ar[n - 1]
	print(ans)


m = 1000000007
l = [1]
z = 1
o = 1
for i in range(2, 1000001):
	z = z * i % m
	o = o * z % m
	l.append(o)
for i in range(int(input())):
	n = int(input())
	print(l[n - 1])


arr = [1] * (10 ** 6 + 1)
fact = []
fact.append(1)
mod = 10 ** 9 + 7
for i in range(1, 10 ** 6 + 1):
	fact.append(fact[i - 1] * i % mod)
for i in range(10 ** 6 + 1):
	arr[i] = fact[i] * arr[i - 1] % mod
t = int(input())
for _ in range(t):
	n = int(input())
	print(arr[n] % mod)


p = 10 ** 9 + 7
t = int(input())
fact = [1]
for i in range(1, 1000001):
	fact.append(i * fact[i - 1] % p)
ans = [1] * 1000000
for i in range(1, 1000000):
	ans[i] = ans[i - 1] * fact[i + 1] % p
for i in range(t):
	n = int(input())
	print(ans[n - 1])


n = int(input())
l = [1, 2, 12]
A = 6
a = 4
for i in range(4, 1000001):
	l.append(A % 1000000007 * a % 1000000007 * l[len(l) - 1] % 1000000007)
	A = A * a % 1000000007
	a += 1
for i in range(0, n):
	o = int(input())
	print(l[o - 1])


p = 1
d = {}
for i in range(1, 1000001):
	p = p * i % 1000000007
	d[i] = p
k = 1
ans = {}
s = 1
for i in d:
	s = s * d[i] % 1000000007
	ans[k] = s
	k += 1
for _ in range(int(input())):
	n = int(input())
	print(ans[n] % 1000000007)


arr = [0] * 1000009
ans = [0] * 1000009
arr[1] = 1
arr[2] = 2
ans[1] = 1
ans[2] = 2
di = 1000000000 + 7
for i in range(3, 1000001):
	arr[i] = arr[i - 1] % di * (i % di) % di
for i in range(3, 1000001):
	ans[i] = ans[i - 1] % di * (arr[i] % di) % di
t = int(input())
for i in range(t):
	n = int(input())
	print(ans[n] % di)


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


lim = 1000007
M = 1000000007
fact = [1] * lim
fact[1] = 1
for i in range(2, lim):
	fact[i] = fact[i - 1] * i % M
dp = [1] * lim
dp[1] = 1
for i in range(2, lim):
	dp[i] = dp[i - 1] * fact[i] % M
t = int(input())
for _ in range(t):
	n = int(input())
	print(dp[n])


md = 1000000007
s = 1
fac = 1
l = []
for i in range(1, 10 ** 6 + 1):
	fac = fac * i % md
	s = s * fac % md
	l.append(s)
t = int(input())
for p in range(t):
	n = int(input())
	print(l[n - 1])


l = [0] * (10 ** 6 + 1)
l[1] = 1
p = 1
m = 10 ** 9 + 7
for i in range(2, 10 ** 6 + 1):
	l[i] = l[i - 1] * (p * i) % m % m
	p *= i
	p = p % m
for u in range(int(input())):
	print(l[int(input())])


def cal(n):
	prod = 1
	fac = 1
	for i in range(1, n + 1):
		fac *= i
		fac = fac % 1000000007
		prod *= fac
		prod = prod % 1000000007
	print(prod)
t = int(input())
while t:
	prod = 1
	fac = 1
	t -= 1
	n = int(input())
	cal(n)


t = int(input())
l = [1]
m = 1000000007
n = 1000001
pro = 1
prof = 1
for i in range(2, n):
	pro = pro % m * (i % m) % m
	prof = prof % m * (pro % m) % m
	l.append(prof)
for _ in range(t):
	a = int(input())
	print(l[a - 1])


d = [1 for i in range(1000001)]
s = 1
for i in range(2, 1000001):
	s = s * i % 1000000007
	d[i] = d[i - 1] * s % 1000000007
for _ in range(int(input())):
	n = int(input())
	print(d[n])


mod = 1000000007
from collections import defaultdict
fact = defaultdict(int)
pfact = defaultdict(int)
fact[0] = 1
pfact[0] = 1
maxn = 10 ** 6
for i in range(1, maxn + 1):
	fact[i] = fact[i - 1] * i % mod
	pfact[i] = fact[i] * pfact[i - 1] % mod
t = int(input())
for _ in range(t):
	n = int(input())
	print(pfact[n])