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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t = int(raw_input())
maxi = 0
num = [0 for i in range(t)]
for i in range(t):
	num[i] = int(raw_input())
	if(num[i]>maxi):
		maxi = num[i]
		
ans = [0 for i in range(maxi+1)]

ans[1]=1
ans[2]=2
for i in range(3,maxi+1):
	ans[i]=(ans[i-1]+(i-1)*ans[i-2])%1000000007
	
for i in range(t):
	print ans[num[i]]%1000000007