Jeju Island Tour

No attempts yetTime limit1sMemory limit128 MB

Problem

Many tourists visit Jeju Island. The island has NN intersections and MM one way roads. Each road runs from one intersection to another, and several roads may connect the same pair of intersections.

The roads on Jeju Island are laid out in a very strange shape. Whichever intersection you start from, you can never follow the roads and get back to the intersection you started at. (So how do the people who live there get to work?)

Two groups are planning a trip around the island. Each group starts at one intersection and travels along the roads. The two groups get along badly, so they must not pass through the same intersection. You have to pick two routes P1P_1 and P2P_2, where PiP_i (1i21 \le i \le 2) starts at intersection sis_i and finishes at intersection tit_i, and the two routes must not share a single intersection. The starting and finishing points must not overlap either. A route PiP_i containing only one intersection is allowed (si=tis_i = t_i).

Write a program that maximizes the total number of intersections on the two routes.

Input

The first line contains the number of test cases TT (1T101 \le T \le 10).

The first line of each test case contains the number of intersections NN and the number of roads MM (1N3001 \le N \le 300, 1M30001 \le M \le 3000). The intersections are numbered from 11 to NN. Each of the next MM lines contains two integers AA and BB describing one road, meaning there is a one way road from intersection AA to intersection BB.

Output

For each test case, print on its own line the largest possible total number of intersections on two routes that satisfy the conditions.