Circuits#8498

Circuits

1 second
128 megabytes
Easy

Consider a digital electric circuit operating with binary signals in a discrete time. It contains input signals, wires, junctions and logical gates. We will use six kinds of logical gates: NOT, AND, NAND, OR, NOR, DFF. Each of them returns one output signal. The amount of input signals and details about return value are showed in the following table.

The scheme will operate in the following manner. Before the first tick of the discrete time each DFF gate is initialized with zero value. Then during certain amount of ticks several junctions (input junctions) will be fed with input values. You are to write a program that will calculate binary values on a certain set of junctions (output junctions).

Your program will be given the description of the logical scheme, the set of junctions in which we are interested and the input values for each consecutive tick of the discrete time.

Input

The input consists of two blocks. First block contains several lines. If the first symbol of a line is a sharp (#), than the line contains a comment. You can ignore it. You can also ignore empty lines. A line describing the input signal looks like INPUT(junction), where junction is the name of the junction. A line describing the interesting junction looks like OUTPUT(junction), where junction is the name of the junction. A junction name consists of small and capital Latin letters and digits and the underline character ( _ ). The length of each name is less than characters.

All other lines of the first block contain the description of new junctions. Such line can look like j1 = op(j2), where j1 and j2 are the names of junctions and op is either NOT or DFF. It can also look like j1 = op(j2[, j3...]), where j's are the junction names and op is AND, NAND, OR or NOR. There will be no more than junctions.

The second block of the input starts with the line INPUT VALUES. Each of the following lines contains a sequence of zeroes and ones. Amount of digits equals to the amount of input signals. You should match these binary values to the input signal values, in the order the input signals given. There are no more than lines in this block. Please refer to the sample for the details.

You may assume that the input data is correct. You may assume that the given circuit will operate correctly.

Output

For each line of the input signal values, print one line containing zeroes and ones. The digits should correspond to the values of the output signals, preserving their order in the input.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading