Under construction

Still being built. Things may change

Quality Inspection

Interview

Time limit1sMemory limit128 MB

Summary
Given triples of parts (one of each type) with PASS or FAIL results, deduce for every part whether it is certainly good, certainly broken, or undetermined.
Level

Medium5 of 10

Topics
Implementation, Brute force, Simulation
Solved
No attempts yet

Problem

A factory produces three kinds of parts: A, B, and C. Each day it makes aa parts of type A, bb of type B, and cc of type C. The parts are numbered consecutively starting from 1 as follows.

  • Type A parts: numbered 1 through aa
  • Type B parts: numbered a+1a+1 through a+ba+b
  • Type C parts: numbered a+b+1a+b+1 through a+b+ca+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 aa, the number of type B parts bb, and the number of type C parts cc, separated by spaces. (1≤a,b,c≤1001 \le a, b, c \le 100)

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

Each of the next NN lines describes one inspection result. Each line contains the type A part number ii, the type B part number jj, the type C part number kk, and the inspection result rr, separated by spaces. r=1r = 1 means PASS and r=0r = 0 means FAIL.

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

Output

Print, over a+b+ca+b+c lines, the verdict for each part from part 1 to part a+b+ca+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

Examples4

  1. Example 1

    Input
    2 2 2
    4
    2 4 5 0
    2 3 6 0
    1 4 5 0
    2 3 5 1
    
    Expected output
    2
    1
    1
    0
    1
    0
    
  2. Example 2

    Input
    1 1 1
    1
    1 2 3 1
    
    Expected output
    1
    1
    1
    
  3. Example 3

    Input
    1 1 1
    1
    1 2 3 0
    
    Expected output
    2
    2
    2
    
  4. Example 4

    Input
    2 1 1
    2
    1 3 4 1
    2 3 4 0
    
    Expected output
    1
    0
    1
    1