Lucy has made too many friends but she does not know how many friends are in her circle. Assume that every relation is mutual. If Lucy is Patty's friend, then Patty is also Lucy's friend. Your task is to help Lucy in keeping track of each person's circle size.

Input Specification

The first line of input contains one integer T (T<=10) specifying the number of test cases to follow. Each test case begins with a line containing an integer N (N<=100000), the number of new relations. Each of the following N lines contains couple of strings denoting the names of two people who have just formed relation, separated by a space. Names will have no more than 20 characters.

Output Specification

Print a line containing one integer, the number of people in the combined circle of two people who have just become friends.


Lucy Patty
Patty Alice
Alice Mira
Tiffany Jayden 


2 3 4 2

hide comments
Vamos: 2013-07-14 09:28:59

@John snow : Try to approach differently.

Last edit: 2013-07-22 08:50:48
P[_]/|/K: 2013-07-14 09:28:59

Thanks to the problem setter for decreasing the time limit.
It made me improve my solution.. :)

John Snow: 2013-07-14 09:28:59

@saurabh kr vats,can you tell where my solution is giving wrong answer

ss: 2013-07-14 09:28:59

@saurabh kr. vats plz tell me, is there may be more than one friend circle???

Last edit: 2013-06-27 18:10:43
technophyle: 2013-07-14 09:28:59

Easy :D

Vamos: 2013-07-14 09:28:59

Circle size of a person A refers to number of people to whom he is related including A.

Last edit: 2013-06-26 13:10:50
Chandan Mittal: 2013-07-14 09:28:59

can someone explain more clearly what does 'circle size' means here?

Last edit: 2013-12-27 22:52:00

Added by:Vamos
Time limit:0.100s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64