Roadside optimization

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

문제

Some of the towns in the province GG are connected with roads; roads always go both ways. The budget to support the road network is scarce, therefore it was decided to leave the bare minimum of the roads. However, if it is currently possible to reach the town BB from the town AA, this possibility must remain even after the reduction.

Help to define the minimum number of roads that must remain.

입력

The first line of the input file contains a single integer TT --- the number of tests (1T50,0001 \le T \le 50\\,000). It is followed by the description of TT tests.

The first line of the test number tt contains a single integer N_tN\_t --- the number of towns (1N_t2001 \le N\_t \le 200).

The following N_tN\_t lines contain N_tN\_t integers; each integer is either 00 or 11. If the line with the number ii has 00 in the jjth position, then the town jj can not be reached from the town ii (even by driving through other towns); if it is 11, then there is a passage. It is assumed that there is a passage from a town to the same town, so there will always be 11 in the iith line in the iith position (1iN_t1 \le i \le N\_t).

It is guaranteed that the sum of N_t2N\_t^2 over all tests is not greater than 50,00050\\,000.

출력

For each test, print a single integer on a separate line --- the minimum number of roads to be kept.