def f_iter(n):
    f = [0] * (n + 1)
    f[1], f[2] = 1, 2

    for i in xrange(3, n + 1):
        f[i] = ((i - 1) * f[i - 2] + f[i - 1]) % 1000000007
    return f


def main():
    cache = f_iter(1000000)
    t = int(raw_input())
    for i in xrange(t):
        n = int(raw_input())
        print cache[n]


if __name__ == '__main__':
    main()