Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.
Teacher Mai has m functions f1,f2,⋯,fm:{1,2,⋯,n}→{1,2,⋯,n}(that means for all x∈{1,2,⋯,n},f(x)∈{1,2,⋯,n}). But Rhason only knows some of these functions, and others are unknown.
She wants to know how many different function series f1,f2,⋯,fm there are that for every i(1≤i≤n),f1(f2(⋯fm(i)))=i. Two function series f1,f2,⋯,fm and g1,g2,⋯,gm are considered different if and only if there exist i(1≤i≤m),j(1≤j≤n),fi(j)≠gi(j).
For each test case print the answer modulo 109+7.
3 3 1 2 3 -1 3 2 1
1
The order in the function series is determined. What she can do is to assign the values to the unknown functions.