A train yard is a complex network of railroad tracks used to store, sort, load, and unload railroad cars. In this problem the tracks are much simpler, and we are only interested in combining two trains into one.
Each of the two trains is made up of several railroad cars. Every car carries a single type of product identified by a positive integer of at most 1,000,000. The two trains arrive from the right on separate tracks. To combine them, at each step you may take the car at the front of either train and attach it to the back of the new train being formed on the left. Once every car of one train has been moved, the remaining cars of the other train are moved to the left one at a time, in order. Eventually every car must be moved to the left.
Depending on which train you pick at each step, the departing train ends up in different orders. For example, by always picking the first train until it is empty you obtain the order 1, 1, 1, 2, 2, 2; by alternating between the two trains you obtain the order 2, 1, 2, 1, 2, 1.
The yard supervisor has been given a desired order of products for the departing train. Given the order of the cars of the two arriving trains, decide whether the desired order can be produced.
The input consists of several test cases.
The first line of each case contains two positive integers $N_1$ and $N_2$, the number of railroad cars in each train. Each train has between 1 and 1000 cars.
The second line contains $N_1$ positive integers (each at most 1,000,000) identifying the products on the first train, listed from the front of the train to the back.
The third line contains $N_2$ positive integers describing the second train in the same format.
The fourth line contains $N_1+N_2$ positive integers giving the desired order for the departing train, in the same format.
A line with $N_1 = N_2 = 0$ marks the end of the input.
For each case, print possible on a line if the desired order can be produced, or not possible if it cannot.