Gates

No attempts yetTime limit3sMemory limit128 MB

Problem

Consider a circuit consisting of nn gates, numbered from 00 to n1n-1. Each gate has some number of inputs and exactly one output. Every input and every output is in one of three states: 00, 1/21/2, or 11.

Each input is connected to exactly one output of some gate, and the input's state equals the state of the output it is connected to. A single output may be connected to any number of inputs.

Gates 00 and 11 are special: they have no inputs at all, and their outputs are always fixed — gate 00 always outputs 00, and gate 11 always outputs 11.

The state of a gate's output (in short, the gate's state) is valid if one of the following holds:

  1. it equals 00 and the gate has more inputs in state 00 than in state 11;
  2. it equals 1/21/2 and the gate has equally many inputs in state 00 as in state 11;
  3. it equals 11 and the gate has more inputs in state 11 than in state 00;
  4. the gate is special (number 00 or 11) and its state is 00 or 11 respectively.

A circuit's state is valid if every gate's state is valid. A gate's state is fixed if the gate has the same state in every valid state of the circuit.

Write a program that, for each gate, decides whether its state is fixed and, if so, determines it.

Input

The first line contains the number of gates nn (2n10,0002 \le n \le 10{,}000).

The next n2n-2 lines describe the gates' connections. Read from top to bottom, they correspond to gates 2,3,,n12, 3, \dots, n-1 in order, and the line for gate ii describes its inputs. Each such line begins with the number of inputs kik_i of that gate (ki1k_i \ge 1), followed by kik_i gate numbers — the gates whose outputs are connected to the successive inputs of gate ii. Numbers on a line are separated by single spaces.

The total number of inputs over all gates does not exceed 200,000200{,}000.

Output

Print nn lines. Line ii corresponds to gate i1i-1 and must contain:

  • 0 — if the state is fixed and equals 00;
  • 1/2 — if the state is fixed and equals 1/21/2;
  • 1 — if the state is fixed and equals 11;
  • ? — if the state is not fixed.

Hint