Jonathan Sumabat is a valued member of his school's tech crew. He has been tasked with managing the audio for the next school assembly. This would normally be fine as Jonathan Sumabat is excellent with technology, however his school's soundboard is broken. The soundboard has knobs that Jonathan Sumabat must turn in order to get the perfect sound. Each knob has a specific value and when each are turned to the correct value the sound that Jonathan Sumabat wants is produced. However, for his school's soundboard when one knob is turned it may also change the value of another knob. Jonathan Sumabat is unaware of this and when the assembly comes around he produces a screeching and unbearable sound. Given information about the soundboard and the knobs Jonathan Sumabat turned, determine the values of each knob that produced this horrible sound.
Input Specification
The first line of input is an integer representing the number of knobs on the soundboard. They are numbered 1 to . Initially, each knob has the value of 0.
The next line is representing the number of knobs that unintentionally change the value of another knob.
The next lines contain 4 space separated values representing what happens when each broken knob is turned:
- The first integer, is the number of the knob that is broken.
- The second integer, is the number of the knob that is affected when the broken knob is turned.
- The third value, , is either the character
+
or the character*
representing the operation that is applied to when is turned. - The last value is an integer representing by how much is affected.
if is+
, otherwise .
When is turned, the value of is increased by if is +
. Otherwise, the value of is multiplied by .
There will never be a set of knobs that change the values of each other infinitely.
The next line is representing the number of times Jonathan Sumabat turns a knob. It is possible that he will turn the same knob multiple times.
The next lines each have two space separated integers:
- The first, represents the knob Jonathan Sumabat turns.
- The next, represents the amount that Jonathan Sumabat increases the knob by.
At any given point, the value of each knob will fit in a 64 bit signed integer.
Output Specification
On a single line, with each value separated by a space, print the value of each knob on the soundboard in ascending order from 1 to .
Sample Input
10
5
4 8 + 2
3 2 * 3
8 2 + 23
2 5 + 1
5 1 * 6
3
4 12
8 2
3 9
Sample Output
0 138 9 12 3 0 0 4 0 0
Comments
When a knob is turned and affects a knob k2, does this knob k2 in turn affect other knobs? Going by the sample input/output, it seems that ex.turning knob 4 affects knob 8, which affects knob 2 (which affects knob 5).
Edit: this is definitely the case, now I go be depressed