$n=<>;/ /,push@{$n-$`},$n-$' for<>;map{print$|x($f|=$b[$_]=$|=grep!$b[$_],@$_)}1..$n