There are N kids, with ids from 1 to N, standing in a queue.
Every kid in this queue has his own candy set, a multiset of candy types that he wants to eat.
Stiff Waist Beast wants to send off these kids, so he’s going to give some candies to them.
Formally, Stiff Waist Beast will put M candies on the table one by one, the ith candy he’s going to put is of type ci. Once the candies on the table contain the candy set of the kid at the front of the queue (i.e. The kid's candy set is a subset of the candies on the table), for every type of the candy in his candy set, he’ll pick one candy of that type from the table. Notice that he'll probably have repeated candy types in his candy set, in this case, he'll get as many candies as the number of that candy type appears in his candy set. Every candy would stay on the table until one has taken it.
After he’d picked all of the candies he want, he’ll leave the queue. And the next kid would move to the front of the queue, start getting candies. i.e. These kids are waiting candies in a queue, no one would start getting candies until all of the kids in front of him has got their candy set.
Now, Pigeon, sidekick of Stiff Waist Beast, is recording the destination of every candy. He’d like to know who had picked the ith candy, or if it was left on the table eventually. Since he’s busy on recording all of the other stuff Stiff Waist Beast is doing, which is definitely important, he’s asking you for help. It’s up to you whether help him or not, but you’ll fail this lab if you don’t :(
Some details you may want to know:
The first line of input contains two positive integers N, M, as described in the statement.
Next, there would be N candy set, each candy set is represented by two lines, the first line contains a single positive integer szi, denoted the size of the candy set of the ith kid. The second line contains szi integers, each denoted one of the candy type in this candy set.
Next, there would be M integers, c1∼ cM as the statement described.
Output M lines, each contains a integer, represents the desination of the candy.