T = int(raw_input())
P = 1000000007
N = 1000000
A = [0]*(N+1)
A[0] = 0
A[1] = 1
A[2] = 2
#X = pow(2,P-2,P)
for i in xrange(3,N+1):
	A[i] = (A[i-1] + ((i-1)*A[i-2]))%P
#print A
for _ in xrange(T):
	N = int(raw_input())
	print A[N]