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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
table = [None] * 1000006
table[0] = 1
table[1] = 1

for i in range(2, 1000006):
	table[i] = (table[i-1] + (i-1)*table[i-2]) % 1000000007

for _ in range(input()):
	people = input()
	print table[people]