Title: Quality Inspection

Problem:
You are responsible for quality control at a manufacturing plant for a certain machine. This machine requires power, a motor, and a cable as components. The plant has a total of a power sources, b motors, and c cables, each numbered from 1 to a, a+1 to a+b, and a+b+1 to a+b+c, respectively. Unfortunately, some of these components may be faulty. The plant needs to determine which components are faulty and which are functioning properly.

The plant conducts inspections by connecting one power source, one motor, and one cable, and testing their operation. If all three components are functioning properly, the test is marked as "pass." If any one of the three components is faulty, the test is marked as "fail." The precision of the machine ensures that faulty components will not accidentally pass the test.

You are given a list of inspection results. Each line in the list contains the numbers of the power source, motor, and cable used in the inspection, along with whether the test passed or failed.

Given the inspection results, create a program to categorize each component as definitely faulty, definitely functional, or undetermined based on the inspection results.

Input:
The input consists of multiple datasets. Each dataset is formatted as follows:
- The first line contains three integers separated by spaces: a, b, and c, representing the number of power sources, motors, and cables, respectively.
- The second line contains a single integer N, representing the number of inspections in the results list.
- The following N lines represent the inspection results. Each line contains four integers i, j, k, and r separated by spaces, where i, j, and k are the numbers of the power source, motor, and cable used in the inspection, and r indicates whether the test passed (r=1) or failed (r=0).

Constraints: 1 ≤ a, b, c ≤ 100, 1 ≤ N ≤ 1000. The number of datasets does not exceed 5.

Output:
For each dataset, output the following for each component (a+b+c lines in total):
- If the component is determined to be faulty based on the inspection results, output 0.
- If the component is determined to be functional based on the inspection results, output 1.
- If the status of the component cannot be determined based on the inspection results, output 2.

Example:
Input
2 2 2
4
2 4 5 0
2 3 6 0
1 4 5 0
2 3 5 1
0 0 0

Output
2
1
1
0
1
0

# Buggy version:
for e in iter(input,'0 0 0'):
 d=[2]*-~sum(map(int,e.split()))
 f=[]
 for _ in[0]*int(input()):
  s,t,u,v=map(int,input().split())
  if v:d[s]=d[t]=d[u]=1
  else:f+=[(s,t,u)]
 for s,t,u in f:
  d[s]=2*(d[t]*d[u]!=1)
  d[t]=2*(d[u]*d[s]!=1)
  d[u]=2*(d[s]*d[t]!=1)
 for x in d[1:]:print(x)


# Fixed version:
for e in iter(input,'0 0 0'):
 d=[2]*-~sum(map(int,e.split()))
 f=[]
 for _ in[0]*int(input()):
  s,t,u,v=map(int,input().split())
  if v:d[s]=d[t]=d[u]=1
  else:f+=[(s,t,u)]
 for s,t,u in f:
  if d[t]*d[u]==1:d[s]=0
  if d[u]*d[s]==1:d[t]=0
  if d[s]*d[t]==1:d[u]=0
 for x in d[1:]:print(x)

# Buggy version:
for e in iter(input,'0 0 0'):
 d=[2]*-~sum(map(int,e.split()))
 f=[]
 for _ in[0]*int(input()):
  s,t,u,v=map(int,input().split())
  if v:d[s]=d[t]=d[u]=1
  else:f+=[(s,t,u)]
 for s,t,u in f:
  if d[t]*d[u]!=1:d[s]=0
  if d[u]*d[s]!=1:d[t]=0
  if d[s]*d[t]!=1:d[u]=0
 print(d[1:],sep='\n')


# Fixed version:
for e in iter(input,'0 0 0'):
 d=[2]*-~sum(map(int,e.split()))
 f=[]
 for _ in[0]*int(input()):
  s,t,u,v=map(int,input().split())
  if v:d[s]=d[t]=d[u]=1
  else:f+=[(s,t,u)]
 for s,t,u in f:
  if d[t]*d[u]==1:d[s]=0
  if d[u]*d[s]==1:d[t]=0
  if d[s]*d[t]==1:d[u]=0
 print(*d[1:],sep='\n')