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.
Each of the $T$ test cases consists of multiple lines.
The 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.
Each 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 = 1$ means player $x$ won the match and $z=0$ means player $y$ won the match.
Each 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$.