FRNDCIRC - FRIEND CIRCLE


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.

Input 

1
4
Lucy Patty
Patty Alice
Alice Mira
Tiffany Jayden 

Output

2
2 3 4 2

hide comments
Satyaki Upadhyay: 2014-08-25 18:41:49

Take care. Requires fast I/O.

sobriquet: 2014-07-14 07:42:21

Good one. AC in one go.

Apoorv Jindal: 2014-01-21 14:10:56

Implementation problems like these make you fall in love with your language. This one needs smart data structures.

Aditya Bahuguna: 2014-01-02 21:17:33

Whoa!!...I cant believe that passed!!....:D

Rishab Kalra: 2013-12-24 19:09:46

why am i getting wrong ans. my submission id is 10731242

Arvind: 2013-12-16 16:00:03

Basic problem, but time limits make it very nice! :)

Kevin Sebastian: 2013-12-16 08:47:35

my submision id 10671030 why am i getting sigsev fault

Vikas Kushwaha: 2013-07-25 14:29:00

Time Limit make this one good> :)

RAJDEEP GUPTA: 2013-07-14 09:28:59

Nice Problem. :)

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

Time limits like 0.1s are very iffy. I'm not sure for Cube, but on Pyramid they were blocking languages with slow startup. Don't change the problem now, but for future reference, rather try to do make 1s time limits and bigger test files.

PS. Problem itself is very nice. Thanks for putting it on SPOJ :)


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