m=1000000007
def f(n):
	if n==1:
		return 1
	if n==2:
		return 2
	return f(n-1)+(n-1)*f(n-2)
dp=[0]*1000009;
dp[1]=1
dp[2]=2
for i in range(3,1000009):
	dp[i]=(dp[i-1]%m+(((i-1)%m)*(dp[i-2]%m))%m)%m
t=input()
for i in range(0,t):
	print dp[input()]