import sys

def vibhuAndMathematics(nset):
	modulo = 10**9 + 7
	tmp = {}
	tmp[1] = 1
	a = 1
	b = 1
	i = iter(sorted(nset))
	try:
		n = i.next()
		while n == 1:
			n = i.next()
		for j in range(2, (10**6 + 2)):
			c = (b + (j-1)*a) % modulo
			while j == n:
				tmp[n] = c
				n = i.next()
			a = b
			b = c

	except StopIteration:
		pass
	ret = []
	for n in nset:
		ret.append(tmp[n])
	return ret

n = int(sys.stdin.readline())
v = []
for i in range(n):
	v.append(int(sys.stdin.readline()))
for o in vibhuAndMathematics(v):
	print(o)