Bad Maths


You are given equations over variables that each take a value of either 11 or −1-1. Every equation has the form a×b=ca \times b = c, where aa and bb are variables and cc is either 11 or −1-1.

Process the equations one by one. For each equation, decide whether it is consistent with the equations accepted so far: that is, whether there still exists an assignment of ±1\pm 1 to all variables that satisfies every previously accepted equation together with the current one.

  • If it is consistent, output Yes and accept the equation.
  • If it is inconsistent, output No and discard the equation (do not use it when checking later equations).

Input

The first line contains an integer nn, the number of equations.

Each of the following nn lines contains a b c, meaning a×b=ca \times b = c, where aa and bb are variable names (nonempty strings of lowercase English letters) and cc is either 11 or −1-1.

Output

For each equation, output a line containing Yes if it is consistent with the equations accepted so far, or No otherwise.

Constraints

  • 1≤n≤5×1051 \le n \le 5 \times 10^5
  • 1≤∣a∣,∣b∣≤101 \le |a|, |b| \le 10
  • c∈{1,−1}c \in \{1, -1\}

Example 1

Input 1
10
c c -1
a b 1
c c 1
d e 1
c e 1
c a 1
b e -1
b b -1
b b -1
e b 1
Output 1
No
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
Explanation
  • c×c=−1c \times c = -1 is impossible for c∈{1,−1}c \in \{1, -1\}, so the answer is No and the equation is discarded.
  • a×b=1a \times b = 1 is accepted.
  • c×c=1c \times c = 1 always holds, so it is accepted.
  • The next three equations are all compatible with an assignment and are accepted. Together they force bb and ee to have the same sign, so b×eb \times e must equal 11.
  • Therefore b×e=−1b \times e = -1 is inconsistent and discarded.
  • Both copies of b×b=−1b \times b = -1 are impossible and discarded.
  • e×b=1e \times b = 1 matches the forced relation, so it is accepted.

Example 2

Input 2
20
c b 1
e c -1
b b 1
d f -1
a d -1
b c 1
d b 1
f e -1
d b 1
e d 1
c d 1
f a -1
e e 1
c b 1
d d 1
d e -1
b a 1
b a 1
d f 1
a f -1
Output 2
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.