You are given a tree with vertices, numbered from to . There is a closed door on every edge.
Each door has exactly one key. These keys are divided among nonempty keyrings, numbered from to . You carry all the keyrings from the beginning.
You choose a starting vertex. You may move through open doors in either direction any number of times. If you are at either endpoint of an edge with a closed door, you may use its key to open it. Once opened, a door remains open forever.
You may use the keyrings in any order. However, once you open a door using a keyring, you must open every door whose key belongs to that keyring before you can open a door using another keyring. You may choose the order of the keys within each keyring.
For every vertex, determine whether it is possible to open all the doors when starting there.
Output a binary string of length , where is if starting at vertex is possible, and otherwise.
Each triple describes an edge between vertices and whose door has its key on keyring .
For each test case, output one binary string of length , without spaces between its characters.