softsort-7

Let us define an easy Sorting Algorithm called SoftSort. SoftSort Sorting algorithm involves use of  IF and ELSE decision statements only. For example : 

To sort two numbers a and b. SoftSort Algorithm's Code is given below.

void print(int a,int b){
    printf( "%d %d\n",a,b);
}
void sort( int a, int b){
    if( b < a )
        print( b, a );
     else
        print( a, b );
}

To sort three numbers a , b and c  . Source Code is given below.

  void print( int a, int b, int c ) {
        printf( "%d %d %d\n", a, b, c );
}
void sort( int a, int b, int c ) {
        if( a < b )
            if( a < c )
                if( b < c )
                    print( a, b, c );
                else
                    print( a, c, b );
            else
                print( c, a, b );
        else
            if( b < c )
                if( a < c )
                    print( b, a, c );
                else
                    print( b, c, a );
            else
                print( c, b, a );
    }

ANI is fascinated with the SoftSort Algorithm and decided to ask an interesting question to KUKU.

What could be the length of source code to sort n numbers using SoftSort Algorithm ?

INPUT:

First line of the input contains an integer t denoting the number of ANI's queries.Next t lines contains an integer n 

denoting the numbers given by ANI to Sort using the above mentioned algorithm.

OUTPUT:

Output consists of t lines each describing the length of Source Code written to sort n numbers given by ANI in 

each corresponding Test Case.    

Since the answer can be very large so print output modulo 10^9+7.

CONSTRAINTS:

1 ≤ t ≤ 10^5 

1 ≤ n ≤ 10^6

SAMPLE INPUT
3
1
2
3

SAMPLE OUTPUT
6
9
21

Explanation

EXPLANATION: 

Refer Given Problem Statement

Source: hackerearth | Difficulty: EASY
Tags: Fundamentals

Mathematics


Solutions:
import math
n=eval(input())
modulus=10**9+7
res=[]


res.append(1)
i=1
while i<=10**6:
	temp=(res[i-1]*i)%modulus		
	res.append(temp)
	i+=1
	
	
 
for i in range(0,n):
	a=eval(input())
	temp=res[a]
	#result=5+2+temp+(temp-2)*2
	result=3+3*temp
	print(result%modulus)
	#print temp
	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
d = {0:1}
i=1
while i<10**6+1:
	d[i] = (i*d[i-1])%(10**9 + 7)
	i += 1
x = int(input())
for elem in range(x):
	y = int(input())
	n = (3*d[y] + 3) % (10**9 + 7)
	print(n)



hashing= [0]*(10**6+1)

MOD= 10**9+7
fact=[0]*(10**6+1)
fact[1]=1
for i in range(2,10**6+1):
	fact[i]=(i%MOD*fact[i-1]%MOD)%MOD
	#print fact[i]


for i in range(1,10**6+1):
	hashing[i]=((3*fact[i]%MOD)+3)%MOD


n= eval(input())
for i in range(n):
	num= eval(input())
	print(hashing[num])


dic = {0:1}
i=1
while i<10**6+1:
	dic[i] = (i*dic[i-1])%(10**9 + 7)
	i += 1
x = int(input())
for elem in range(x):
	y = int(input())
	n = (3*dic[y] + 3) % (10**9 + 7)
	print(n)





'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
di = {0:1}
i=1
while i<10**6+1:
	di[i] = (i*di[i-1])%(10**9 + 7)
	i += 1
x = int(input())
for elem in range(x):
	y = int(input())
	n = (3*di[y] + 3) % (10**9 + 7)
	print(n)


hashing= [0]*(10**6+1)

MOD= 10**9+7
fact=[0]*(10**6+1)
fact[1]=1
for i in range(2,10**6+1):
	fact[i]=(i%MOD*fact[i-1]%MOD)%MOD

for i in range(1,10**6+1):
	hashing[i]=((3*fact[i]%MOD)+3)%MOD

n= eval(input())
for i in range(n):
	num= eval(input())
	print(hashing[num])


max_num = 1000001
factorial = [1]*(max_num + 1)
mod_val = 10**9 + 7
for n in range(1, len(factorial)):
	factorial[n] = n*factorial[n-1] % mod_val  

for _ in range(eval(input())):
	n = eval(input())
	print((3*factorial[n] + 3) % mod_val)