Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Geek and City
Easy Accuracy: 53.5% Submissions: 258 Points: 2

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.

Note:
1. All the cities are numbered from 1 to N.
2. No two cities have multiple roads.
3. No city has self road

Input:
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

Constraints:
1. 1 <= T <= 100

2. 1 <= N <= 50
3. 0 <= M <= min(1000, N*(N-1)/2)

Example:
Input:

2
4 2
1 2
3 4

5 5
1 2
2 3
3 4
4 5
5 1

Output:
1
0