In this problem you must determine the output of a logic circuit made of one or more inputs, zero or more two-input AND/OR gates, and a single output. Each circuit is drawn with plain ASCII characters.
Wires are drawn with three characters: a horizontal segment is a dash - (ASCII 45), a vertical segment is a vertical bar | (ASCII 124), and a junction is a plus + (ASCII 43). Inputs are the capital letters A through Z, and the single output is a question mark ?.
AND and OR gates are drawn exactly as shown below, and they always appear in this orientation:
:\
: )
:/
AND gate
:\
: >
:/
OR gate
The two gate inputs enter on the left and the gate output leaves on the right:
-:\
: )-
-:/
Gate with inputs
Any gate input or output may be inverted. An inversion is marked by a lowercase letter o (ASCII 111) placed at that input or output location:
-o:\
: )o-
--:/
An inverted top input and an inverted output
The figure below is a small but complete logic circuit with two inputs and one output:
A-o:\
: )o-?
B--:/
Two logic inputs and the output
Every circuit obeys these rules:
A circuit diagram in the input ends with a line whose first column holds a single asterisk *. The lines that follow list the input states, one per line: each is a string of twenty-six 0 or 1 characters, where the first character is the state of input A, the second the state of input B, and so on. Input values for letters the circuit does not use are simply ignored. The list of input states ends with another line whose first column holds a single asterisk *.
After the asterisk that ends a list of input states comes another circuit diagram, followed by its own list of input states, followed by another circuit diagram and its input states, and so on until the end of the file. The file always contains at least one circuit together with at least one set of inputs for that circuit.
For each circuit, print the value of its output (0 or 1) on its own line, one line for each set of input values listed after that circuit. Separate the block of outputs for one circuit from the block for the next with a single blank line.