A tournament consisting of n participants is currently taking place. The pla
At the current state, some matches have ended, and others are yet to start. You are given the results of all ended matches. Write a program to determine whether it is possible for pla
You are given T independent test cases. Solve each of them.
The first line of input consists of a single integer T(1≤T≤100), indicating the number of test cases. Then TT test cases follow.
Each of the T test cases consists of multiple lines.
The first line contains three integers n,m1,m2(1≤n≤500,1≤m1,m2≤1000), indicating the number of participants, the number of ended matches and the number of upcoming matches.
Each of the next m1 lines contains three space-separated integers x,y,z(1≤x,y≤n,x!=y,0≤z≤1), indicating an ended match between pla
Each of the next m_2m2 lines contains two space-separated integers x,y(1≤x,y≤n,x!=y), indicating an upcoming match between pla
2
4 2 1
2 3 1
3 2 1
1 4
4 2 2
2 3 1
2 4 1
1 2
3 4
YES
NO