Let x_1,x_2,x_3,… be variables. n constraints of form x_i=x_j or x_i=x_j are given. The task asks for whether it is possible to assign values to the variables so that all constraints can be satisfied. For example, if the constraints are x_1=x_2,x_2=x_3,x_3=x_4,x_1=x_4, then those constraints cannot be satisfied simultaneously.
The first line of the input is an integer t representing the number of instances to solve. The instances are independent. For each instance, the first line is an integer n representing the number of constraints to be satisfied. In the following n lines, each line has three integers i,j,e representing an equality/inequality constraint. If e=1, the constraint shall be x_i=x_j. If e=0, the constraint shall be x_i=x_j.
The output has t lines. The k-th line of the output is a string YES or NO. Output YES if the constraints in that instance can be satisfied and NO otherwise.