Quality Inspection

No attempts yetTime limit1sMemory limit128 MB

Problem

A factory produces three kinds of parts: A, B, and C. Each day it makes $a$ parts of type A, $b$ of type B, and $c$ of type C. The parts are numbered consecutively starting from 1 as follows.

  • Type A parts: numbered 1 through $a$
  • Type B parts: numbered $a+1$ through $a+b$
  • Type C parts: numbered $a+b+1$ through $a+b+c$

Not every part is made perfectly, so some parts may be defective. Every day the factory inspects parts as follows.

  • Take one part of each type A, B, and C, connect them, and turn the machine on.
  • If all three parts are good, the machine runs correctly and the inspection is a PASS.
  • If at least one of the three parts is broken, the machine malfunctions and the inspection is a FAIL.

The inspection is extremely precise, so a broken part mixed in never passes by chance. In other words, the three parts used in any passing inspection are guaranteed to all be good.

However, the person in charge is lazy and sometimes stops before running enough inspections. Given the list of inspection results for one day, determine, for each part, which of the following three it is.

  • Good: it can be determined with certainty that the part is good.
  • Broken: it can be determined with certainty that the part is broken.
  • Unknown: the given inspection results alone cannot determine whether the part is good or broken.

Input

The first line contains the number of type A parts $a$, the number of type B parts $b$, and the number of type C parts $c$, separated by spaces. ($1 \le a, b, c \le 100$)

The second line contains the number of inspections $N$. ($1 \le N \le 1000$)

Each of the next $N$ lines describes one inspection result. Each line contains the type A part number $i$, the type B part number $j$, the type C part number $k$, and the inspection result $r$, separated by spaces. $r = 1$ means PASS and $r = 0$ means FAIL.

Part numbers use the global numbering defined above, so $1 \le i \le a$, $a+1 \le j \le a+b$, and $a+b+1 \le k \le a+b+c$.

Output

Print, over $a+b+c$ lines, the verdict for each part from part 1 to part $a+b+c$, one per line.

  • 0 if the part is broken
  • 1 if the part is good
  • 2 if it cannot be determined whether the part is good or broken