Under construction

Still being built. Things may change

Oil Trails

Time limit2sMemory limit512 MB

Summary
Given an undirected multigraph of oil trails, decide whether all edges can be covered by a walk that never returns to a house without visiting another one first.
Level

Medium4 of 10

Topics
Graph, Implementation
Solved
No attempts yet

Problem

Mike owns many houses. Every morning he wakes up in one of them, drives back and forth between his houses until he is tired, and goes to bed in whichever house he stopped at. Oil leaks from his car, so each drive from one house to another leaves one oil trail between those two houses.

Servants live in Mike's houses, and they sometimes drive between the houses as well. Their cars leak oil too, so at the end of the day the trails alone do not say who left them.

Neither Mike nor a servant ever returns to the house they left without visiting a different house first, so no trail joins a house to itself. Driving the same pair of houses twice leaves two trails.

You are given the number of houses at the end of one day and the number of oil trails between each pair of houses. Decide whether, based only on this information, it is possible that Mike left every trail himself.

Input

The first line contains the number of test cases TT (1≤T≤10001 \le T \le 1000).

Each test case is given on two lines. The first line contains the number of houses nn (2≤n≤1002 \le n \le 100), numbered 00 through n−1n-1. The second line begins with the number of triples kk (0≤k≤n(n−1)/20 \le k \le n(n-1)/2), followed by kk triples. A triple x y zx\ y\ z means there are zz oil trails between house xx and house yy (0≤x,y≤n−10 \le x, y \le n-1, x≠yx \ne y, 1≤z≤51 \le z \le 5). Trails have no direction, so if the triple x y zx\ y\ z occurs then y x zy\ x\ z is assumed to exist but does not appear in the input. Each pair of houses appears in at most one triple, and a pair that appears in no triple has no trails between it.

Output

For each test case print yes on its own line if Mike could have left every oil trail himself, and no otherwise.

Examples1

  1. Example 1

    Input
    5
    3
    3 0 1 1 0 2 1 1 2 1
    3
    2 0 1 1 0 2 2
    4
    2 0 1 2 2 3 2
    3
    1 0 2 3
    2
    0
    
    Expected output
    yes
    yes
    no
    yes
    yes