Server Time: Sun Jan 21, 2018 11:57 pm
Welcome ( logout
1417 - Forwarding Emails
  PDF (English) Statistics Forum
Time Limit: 3 second(s) Memory Limit: 32 MB

"... so forward this to ten other people, to prove that you believe the emperor has new clothes."

Aren't those sorts of emails annoying?

Martians get those sorts of emails too, but they have an innovative way of dealing with them. Instead of just forwarding them willy-nilly, or not at all, they each pick one other person they know to email those things to every time - exactly one, no less, no more (and never themselves). Now, the Martian clan chieftain wants to get an email to start going around, but he stubbornly only wants to send one email. Being the chieftain, he managed to find out who forwards emails to whom, and he wants to know: which Martian should he send it to maximize the number of Martians that see it?


Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with a line containing an integer N (2 ≤ N ≤ 50000) denoting the number of Martians in the community. Each of the next N lines contains two integers: u v (1 ≤ u, v ≤ N, u ≠ v) meaning that Martian u forwards email to Martian v.


For each case, print the case number and an integer m, where m is the Martian that the chieftain should send the initial email to. If there is more than one correct answer, output the smallest number.

Sample Input

Output for Sample Input



1 2

2 3

3 1


1 2

2 1

4 3

3 2


1 2

2 1

5 3

3 4

4 5

Case 1: 1

Case 2: 4

Case 3: 3


Problem Setter: Wheeler Zachary J
Special Thanks: Jane Alam Jan
Developed and Maintained by
Copyright © 2012
LightOJ, Jane Alam Jan