#d2851. Good Permutations
Good Permutations
Good Permutations
Problem Description
For every permutation of length , we can build a graph from it in the following two ways:
- For each , find the largest with and , and add an undirected edge between and .
- For each , find the smallest with and , and add an undirected edge between and .
Note that the edges are built between the corresponding indices .
How many permutations of length are there such that the resulting graph contains a cycle?
The number of permutations may be very large; output it modulo .
Input Format
The first line gives one integer (), the number of test cases.
Lines to each give one integer (), the length of the permutation.
Output Format
Output, modulo , the number of permutations satisfying the condition.
Sample Input
1
4
Sample Output
16