def dp():
   
    d = [0]*1000002
    
    d[1]=1
    d[2]=2
    d[3]=4
    
    
    for i in range(4,1000001):
        d[i] =d[i-1] + (i-1)*d[i-2];
        d[i]=d[i]%(10**9+7)
    return d

T = int(raw_input())
a=[]
for i in range(T):
    data = int(raw_input())
    a.append(data)
    
Array = dp()
for item in a:
    print Array[item]