African Sort
题号:NC209978
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Roundgod has a permutation of length . She plans to sort the permutation in ascending order with an algorithm depends on luck. At any time, Roundgod could spend  money to choose a subset  of indices and then uniformly shuffle the values in corresponding positions, where  means the size of . She wants to know the expected value of minimum cost to sort the permutation under the optimal decision. 
Only one permutation can't show Roundgod's luck clearly, so lzr gives Roundgod  permutations. It can be proved that the expected values can always be written in reduced fraction , where  is not a multiple of Please tell Roundgod the answer for each permutation by  , where is the multiplicative inverse modulo .

输入描述:

The first line contains two integers .
For the following  lines, each contains  integers describing one permutation.

输出描述:

For each permutation, print a line of a single integer indicating the answer.
示例1

输入

复制
2 2
1 2
2 1

输出

复制
0
4
示例2

输入

复制
5 1
3 2 5 1 4

输出

复制
332748129