Stand in a Line

All the people in the byteland want to stand in a line in such a way that no person stands closer to the front of the line than his father. You are given the information about the people of the byteland. You have to determine the number of ways the bytelandian people can stand in a line. Input First line of the input contains T (T < 14) the number of test case. Then following lines contains T Test cases. Eachtestcasestartswith2integersn(1≤n≤40000)andm(0≤m<n). nisthenumber of people in the byteland and m is the number of people whose father is alive. These n people are numbered 1...n. Next m line contains two integers a and b denoting that b is the father of a. Each person can have at most one father. And no person will be an ancestor of himself. Output For each test case the output contains a single line denoting the number of different ways the soldier can stand in a single line. The result may be too big. So always output the remainder on dividing ther the result by 1000000007. Sample Input 3 32 21 31 30 31 21 Sample Output 2 6 3