Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2013 /round2 /permutations.md
wjomlex's picture
2013 Problems
c623d8c verified

In this problem you need to count number of possible permutations p of the first N integers, given N-1 constraints of the form pi < pj.

Input

The first line contains an integer T, T ≤ 20, followed by T test cases. Each test case begins with an integer N, N ≤ 1,000, which is the number of integers in the permutation. The next N - 1 lines each contain a single constraint in the following format: "i sign j", where 0 ≤ i, jN - 1 and sign is either "<**" or "**>", which denotes whether the i-th element of the permutation should be less than or greater than the j-th element.

It is guaranteed that it is not possible to partition indices into two disjoint sets A and B such that there is no constraint involving elements from both A and B.

Output

For each test case, output one single line with the number of permutations that satisfy all the constraints, following the output format shown in the example. The answer may be very large, so you should give the result modulo 1,000,000,007.