x = 1000000007
nmax = 1000000
res = [0] * nmax
res[0] = 1
res[1] = 1
for i in xrange(2, nmax):
    res[i] = (res[i-1] + (i-1)*res[i-2]) % x
t = int(raw_input())
for i in xrange(t):
    n = int(raw_input())   
    print res[n]