Roundgod and kimoyami are playing the graph game on a directed graph. Given a directed graph G=(V,E)G=(V,E) and a source vertex s\in Vs∈V, the graph game (G,s) is defined as follows:
Roundgod is not an expert at this game and is often beaten by kimoyami. He remembered the famous quote, "If you can't beat them, join them!'', and then came up with the notion of join of graph games.
Given a nonempty collection of k(k>0) graph games (G1,s1),…,(Gk,sk). The join of the kk games is also a game with the following definition:
Now, given a collection of k graph games, (G1,s1),…,(Gk,sk), Roundgod then needs to choose a nonempty subset from the k games and play with kimoyami on the join of the chosen games. Roundgod wonders, how many ways are there to choose such a nonempty subset so that he may win the game under the optimal strategy of both pla
The first line contains an integer T(1≤T≤5), denoting the number of test cases.
For each test case, the first line of the input contains an integer k(1≤k≤106), denoting the number of graph games in the collection.
Then the desc
For the desc
Then mi lines follow, each line contains two integers u,v(1≤u,v≤ni,u!=v), denoting an edge in the graph of the ith graph game. Note that it is possible for the graph to have multiple edges, but not self loops.
It is guaranteed that for each test case, i=1∑kni≤2×106 and i=1∑kmi≤2×106
2
1
4 3 1
1 2
1 3
3 4
3
2 2 1
1 2
2 1
2 1 1
1 2
2 1 2
1 2
1
2