John and the Magic Box

아직 제출이 없습니다시간 제한12초메모리 제한256 MB

문제

This is an interactive problem.

John has an array of nn mysterious integers. He has an access to a magic box that can combine two integers into one. Let xyx \circ y be the result of combining two integers, xx and yy, with this magic box. After a lot of experiments, John has noticed that the magic box has the following properties:

  • xy=yxx \circ y = y \circ x
  • x(yz)=(xy)zx \circ (y \circ z) = (x \circ y) \circ z

John has qq cousins, and each of them likes all the integers in his array except some kk of them. John wants to give gifts to all his cousins, so he wants to give each cousin the combination of all his integers except the kk this cousin doesn't like.

John likes his cousins, but his magic box is old and worn off because of his intense experiments. He is willing to use the box at most 4(n+q+qk)4 (n + q + q \cdot k) times. Help him get all the required combinations!

힌트

In each test, the rules for the magic box are fixed and don't depend on your queries. Different rules are used for different tests. It is guaranteed that the magic box satisfies the conditions from the problem statement.

In the sample test, the operation performed by the magic box is assumed to be bitwise OR.