Given a tree. For each node of the tree is a collection of items that can be placed in the vertex. Each element has a weight - a positive integer. For each edge of the tree defined by the ratio between the peaks, namely, it is known which of the two vertices must be an element with a lower weight. Required to determine the number of different ways to choose the vertices of a tree on the one element that all relations on the edges are respected. Miscellaneous items from the set of one vertex can have the same weight.
The first line contains the number of vertices n (1 ≤ n ≤ 1000) in the tree. Followed by n lines, the i-th row is given a list of valid elements in the vertex i. The string begins with an integer k (1 ≤ k ≤ 1000) - number of elements. Followed by k integers
wj (1 ≤
109) - the weight of elements.
Further, the input data contains n - 1 lines, each of whom recorded two distinct integers a, b (1 ≤ a, b ≤ n), which means that the tree is an edge between vertices a and b, and in the top of a must be placed in an element of lesser weight than the top of b.
Print the number of ways by modulo 1000000007.
4 5 1 2 3 4 5 3 2 3 6 2 3 5 1 2 1 2 1 3 4 2