{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eA tournament consisting of $n$ participants is currently taking place. The players are numbered from $1$ to $n$. Every match is between two participants, and there are no draws. The participant who wins the most matches wins the entire tournament; if there are multiple participants tied at the first place, all of them win the tournament.\u003cbr\u003e\u003cbr\u003eAt 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 player $1$ to win the tournament.\u003cbr\u003e\u003cbr\u003eYou are given $T$ independent test cases. Solve each of them.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of input consists of a single integer $T(1\\leq T\\leq 100)$, indicating the number of test cases. Then $T$ test cases follow.\u003cbr\u003e\u003cbr\u003eEach of the $T$ test cases consists of multiple lines.\u003cbr\u003e\u003cbr\u003eThe first line contains three integers $n,m_1,m_2(1\\leq n\\leq 500,1\\leq m_1,m_2 \\leq 1000)$, indicating the number of participants, the number of ended matches and the number of upcoming matches. \u003cbr\u003e\u003cbr\u003eEach of the next $m_1$ lines contains three space-separated integers $x,y,z(1\\leq x,y \\leq n,x \\neq y,0\\leq z \\leq 1)$, indicating an ended match between player $x$ and player $y$ , $z \u003d 1$ means player $x$ won the match and $z\u003d0$ means player $y$ won the match. \u003cbr\u003e\u003cbr\u003eEach of the next $m_2$ lines contains two space-separated integers $x,y(1 \\leq x,y \\leq n,x \\neq y)$, indicating an upcoming match between player $x$ and player $y$."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, if it is possible of player $1$ to win the tournament, print a line $\\texttt{YES}$; otherwise print a line $\\texttt{NO}$."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n4 2 1\r\n2 3 1\r\n3 2 1\r\n1 4\r\n4 2 2\r\n2 3 1\r\n2 4 1\r\n1 2\r\n3 4\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYES\r\nNO\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}