Nobody Gets Their Own Hat

easy combinatorics math number-theory dp 1000 ms · 256 MB

Nobody Gets Their Own Hat

n guests check their hats at the door. At the end of the party the cloakroom attendant hands the hats back in a uniformly random order — one hat per guest, each hat used exactly once.

A return order is perfect chaos if no guest receives their own hat, i.e. the hats come back according to a permutation of the n guests with no fixed point.

For each of q independent parties, you are told the number of guests n. Count how many perfect-chaos return orders are possible, modulo 1 000 000 007.

By convention, with 0 guests there is exactly one (empty) way to return hats, and it counts as perfect chaos; with 1 guest the single hat must return to its only owner, so there are 0 perfect-chaos orders.

Input

The first line contains a single integer q (1 ≤ q ≤ 10^5), the number of parties.

Each of the next q lines contains a single integer n (0 ≤ n ≤ 10^6), the number of guests at that party.

Output

For each party, print one line with a single integer: the number of permutations of the n hats with no fixed point, modulo 1 000 000 007.

Notes

In the first example, with n = 3 guests the permutations with no fixed point are (2,3,1) and (3,1,2), so the answer is 2. With n = 4 there are 9 such permutations.

Example 1

Input

5
0
1
2
3
4

Output

1
0
1
2
9

Example 2

Input

6
5
6
7
8
9
10

Output

44
265
1854
14833
133496
1334961

Hints · reveal one at a time if you're stuck

Hint 1

Try small cases by hand: how many fixed-point-free arrangements are there for 0, 1, 2 and 3 guests? Then think about where guest 1's hat goes.

Hint 2

Fix the guest who receives guest 1's hat and look at what happens to that guest's own hat. Either it goes back to guest 1, or it does not, and each case reduces to a smaller instance of the same problem.

report an issue Prefer your own editor? sooks prep 70 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.