The Mysterious X Network

No attempts yetTime limit1sMemory limit128 MB

Problem

École polytechnique — nicknamed “X” — is famous for its network of camarades: former students of the school. Whenever a camarade needs something (money, a job, and so on), they can call on this network for help. To reach another camarade, not necessarily from the same class year, one can always find a chain of intermediate camarades who know one another. The camarade relationship is symmetric (if one knows the other, the other knows the first), and thanks to the network there is always a way to reach anybody.

Your task is to minimize the number of these intermediate camarades on the chain between two given people.

Input

The first line contains an integer NN (1N1051 \le N \le 10^5), the number of camarades, labeled from 00 to N1N-1.

Each of the next NN lines describes one camarade: it starts with that camarade's label cc, followed by the number ncn_c of camarades that cc knows (nc<100n_c < 100), followed by the ncn_c labels of those camarades. All integers on a line are separated by single spaces.

The last line contains two labels c1c_1 and c2c_2 (c2c1c_2 \ne c_1): c1c_1 is the camarade seeking help and c2c_2 is the camarade whose help is sought.

Output

Print three integers separated by single spaces: c1c_1, c2c_2, and the minimal number of intermediate camarades needed to reach c2c_2 from c1c_1.

The intermediate camarades are those strictly between c1c_1 and c2c_2 on a shortest chain; if c1c_1 and c2c_2 know each other directly, this number is 00.