The new building of the computer engineering department has several elevators and no stairs. To make lecture rooms and offices easier to reach, the manufacturer set each elevator to stop only at certain predefined floors. Some elevators stop only at odd floors, some only at even floors. It goes further than that: the buttons inside and outside an elevator work only for the floors that elevator is assigned to stop at. Faculty members now reach their destination floors faster, but people who do not know the building, students in particular, get confused.
A person p is on floor i and wants to go to floor j. To spend the least travel time, which elevator should p take, and on which floors should p transfer to which elevators? Write p's travel path as i=f1→f2→⋯→fk=j. The travel time to minimize is
∑r=1k−1∣fr−fr+1∣
One leg fr→fr+1 of the path is possible only when a single elevator stops at both fr and fr+1. Write a program that helps the people who use these elevators.
The input holds several test cases. The first line of a test case gives the number of elevators n (1≤n≤10), then the source floor and the destination floor. Line i of the next n lines starts with mi (2≤mi≤150), the number of floors at which elevator i may stop, followed by mi floor numbers. Every floor number is a non-negative integer smaller than 150. The floor numbers are not guaranteed to be sorted.
The input ends with a line containing 0 0 0, which you do not process.
For each test case, print on one line the minimum travel time needed to reach the destination floor from the source floor. A way from the source floor to the destination floor always exists.