arr = []
t=int(raw_input())
for k in range(t):
    arr.append(int(raw_input()))
maximum = max(arr)

table=[0 for x in range(maximum+1)]
table[1]=1
table[2]=2
for i in range(3,maximum+1):
    table[i]=(table[i-1]+(i-1)*table[i-2])%1000000007
for i in range(t):
    print table[arr[i]]