#The solution in Python3 is as follows:
if __name__ == '__main__':
N = [0] * 1000000
n = 1
for i in range(1, 1000001):
n = (n * i) % 1000000007
N[i - 1] = n
T = int(input())
for t in range(0, T):
n = int(input())
print(3*(N[n - 1] + 1) % 1000000007)
#Keep visiting for more solutions of HackerEarth problems in Python 3.Thank you!!!