Escaped from NEF

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

A cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. Multiedges (multiple edges between a pair of vertices) and loops (edges that connect a vertex to itself) are not allowed in a cactus.

You are given a directed graph GG with nn vertices with the following property. Consider an undirected graph GG' with nn vertices built as follows: for each directed edge (u_i,v_i)(u\_i, v\_i) in GG, add an undirected edge u_i,v_i\\{ u\_i, v\_i \\} to GG'. Then GG' is a cactus.

Find the number of ordered pairs of vertices (x,y)(x, y) such that there exists a path from vertex xx to vertex yy in GG. Assume that a path from a vertex to itself always exists.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1051 \le t \le 10^5). Description of the test cases follows.

The first line of each test case contains two integers nn and mm, denoting the number of vertices and the number of edges in GG (2n250,0002 \le n \le 250\\,000; n1m3(n1)2n - 1 \le m \le \left\lfloor \frac{3(n-1)}{2} \right\rfloor).

Each of the next mm lines contains two integers u_iu\_i and v_iv\_i, denoting an edge in GG directed from u_iu\_i to v_iv\_i (1u_i,v_in1 \le u\_i, v\_i \le n; u_iv_iu\_i \ne v\_i).

The undirected graph consisting of undirected edges u_i,v_i\\{ u\_i, v\_i \\} is a cactus.

It is guaranteed that the sum of nn over all test cases does not exceed 250,000250\\,000.

출력

For each test case, print the number of ordered pairs (x,y)(x, y) such that vertex yy is reachable from vertex xx in GG.