Server Time: Wed Feb 26, 2020 2:44 pm
Welcome ( logout
C - The Queue
PDF (English) Ranklist
Time Limit: 2 second(s) Memory Limit: 32 MB

On some special occasions Nadia's company provide very special lunch for all employees of the company. Before the food is served all of the employees must stand in a queue in front of the food counter. The company applied a rule for standing in the queue. The rule is nobody can stand anywhere in front of his supervisor in the queue. For example, if Abul is the supervisor of Babul and Abul stands in kth position from the front of the queue, then Babul cannot stand at any position in between 1 and k - 1 from front of the queue.

The company has N employees and each of them has exactly one supervisor except one (CEO) who doesn't have any supervisor.

You have to calculate in how many ways the queue can be created. For this problem, you can safely assume that in at least one way the queue can be created.


Input starts with an integer T (≤ 700), denoting the number of test cases.

Each case starts with a line containing an integer N (1 ≤ N ≤ 1000). Each of the following N - 1 lines will contain two integers a and b (1 ≤ a, b ≤ N, a ≠ b), which denotes that a is the supervisor of b. For the sake of simplicity we are representing each employee by an integer number. Assume that the given input follows the restrictions stated above.


For each case, print the case number and the number of ways to create the queue. The result can be large, print the result modulo 1000 000 007.

Sample Input

Output for Sample Input



2 1

2 3

3 4

3 5

Case 1: 8


Problem Setter: Md. Arifuzzaman Arif
Special Thanks: Jane Alam Jan
Developed and Maintained by
Copyright © 2012
LightOJ, Jane Alam Jan