Given a tree. For each node of the tree, there 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, the ratio between the vertices is defined; namely, it is known which of the two vertices must contain an element with a lower weight. You are required to determine the number of different ways to choose one element for each vertex of the tree such that all relations on the edges are respected. Different items from the set of one vertex can have the same weight.
The first line contains the number of vertices (1 \le n \le 1000) in the tree.
Next, there are lines, where the -th line contains a list of valid elements in vertex . The line begins with an integer (1 \le k \le 1000) — the number of elements. Then follow integers w_j (1 \le w_j \le 10^9) — the weights of the elements.
Further, the input contains n - 1 lines. Each line contains two distinct integers , (1 \le a, b \le n), indicating that there is an edge between vertices and , and in vertex there must be an element of lesser weight than in vertex .
Print the number of ways modulo .
Ejemplo 1