Two Longest Paths
Tekuhp is a tourist city. There are N intersections in the city, connected with M one-way roads. Each one-way road connects from some intersection to another. There maybe many roads that connect a pair of intersections. To make the city very amazing, the roads are constructed so that it is not possible to start at some intersection, travel along the roads, and return to the starting intersection. (It remains a strange secret how people of Tekuhp return home from work each day.)
There are two groups of tourists planning to visit the city. They want to travel along the roads from some intersection to another. However, both groups do not want to run into each other. So they want two paths P_1 and P_2, each P_i, for 1≤ i ≤ 2, starts at some intersection s_i and ends at intersection t_i, such that both paths share no intersections, including the starting and the ending intersections. However, it is possible that a path P_i may contain only one node, i. e., s_i = t_i.
Tourists also want to visit many places. Since you are a good planner, you want to maximize the total number of intersections in both paths.
Input
First line of the input contains an integer T (1 ≤ T ≤ 10), the number of test cases. After that T test cases follow.
Each test case starts with integers N and M (1 ≤ N ≤ 300; 1 ≤ M ≤ 3000), where N denotes the number of intersections and M denotes the number of roads. The intersections are numbered from 1 to N. After that M lines, describing road connection, follow. Each line contains two integers A and B denoting that there is a one-way road from intersection A to intersection B.
Output
The output must contain T lines, each line for each test case. For each test case, the output contains an integer Ldenoting the maximum number of intersections in two nonintersecting paths.