Given N cities, some of them have roads in between them. Geek is in city 1. The task is to find the minimum number of roads needed to construct so that geek can visit any city from any other city.
1. All the cities are numbered from 1 to N.
2. No two cities have multiple roads.
3. No city has self road
1. The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
2. The first line of each test case contains two space_separated integers N and M.
3. Next M lines contain two space-separated integers u and v, represents a road between cities u and v
Output: For each test case, print the answer
1. 1 <= T <= 100
2. 1 <= N <= 50
3. 0 <= M <= min(1000, N*(N-1)/2)
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes