/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
int testCase = 1 ;
Scanner sc
= new Scanner
( System .
in ) ;
boolean first = true ;
while ( sc.hasNextLine ( ) ) {
if ( ! first)
first = false ;
int n = sc.nextInt ( ) ;
Map
< String , Integer
> wordToNum
= new HashMap
<> ( ) ; Map
< Integer , String
> numToWord
= new HashMap
<> ( ) ;
for ( int i = 0 ; i < n; ++ i) {
wordToNum.put ( word, i) ;
numToWord.put ( i, word) ;
}
int m = sc.nextInt ( ) ;
List< ArrayList< Integer>> adj = new ArrayList<> ( ) ;
for ( int i = 0 ; i < n; ++ i) adj.add ( new ArrayList<> ( ) ) ;
int [ ] indegree = new int [ 101 ] ;
for ( int i = 0 ; i < m; ++ i) {
String u
= sc.
next ( ) , v
= sc.
next ( ) ; adj.get ( wordToNum.get ( u) ) .add ( wordToNum.get ( v) ) ;
indegree[ wordToNum.get ( v) ] ++;
}
boolean [ ] vis = new boolean [ 101 ] ;
PriorityQueue< Integer> queue = new PriorityQueue( ) ;
for ( int i = 0 ; i < n; ++ i) {
if ( indegree[ i] == 0 ) {
queue.add ( i) ;
vis[ i] = true ;
}
}
List< Integer> topoSort = new ArrayList<> ( ) ;
while ( ! queue.isEmpty ( ) ) {
int u = queue.poll ( ) ;
topoSort.add ( u) ;
for ( int j = 0 ; j < adj.get ( u) .size ( ) ; ++ j) {
if ( ! vis[ adj.get ( u) .get ( j) ] ) {
if ( -- indegree[ adj.get ( u) .get ( j) ] == 0 ) {
queue.add ( adj.get ( u) .get ( j) ) ;
vis[ adj.get ( u) .get ( j) ] = true ;
}
}
}
}
StringBuilder sb = new StringBuilder( "" ) ;
for ( int i = 0 ; i < topoSort.size ( ) ; ++ i) {
if ( i == 0 )
sb.append ( numToWord.get ( topoSort.get ( i) ) ) ;
else
sb.append ( " " + numToWord.get ( topoSort.get ( i) ) ) ;
}
System .
out .
println ( "Case #" + ( testCase
++ ) + ": Dilbert should drink beverages in this order: " + sb.
toString ( ) + "." ) ;
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJICBpbnQgdGVzdENhc2UgPSAxOwoKICAgICAgICBTY2FubmVyIHNjID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCiAgICAgICAgYm9vbGVhbiBmaXJzdCA9IHRydWU7CiAgICAgICAgd2hpbGUgKHNjLmhhc05leHRMaW5lKCkpIHsKCiAgICAgICAgICAgIGlmICghZmlyc3QpCiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oKTsKCiAgICAgICAgICAgIGZpcnN0ID0gZmFsc2U7CgogICAgICAgICAgICBpbnQgbiA9IHNjLm5leHRJbnQoKTsKCiAgICAgICAgICAgIE1hcDxTdHJpbmcsIEludGVnZXI+IHdvcmRUb051bSA9IG5ldyBIYXNoTWFwPD4oKTsKICAgICAgICAgICAgTWFwPEludGVnZXIsIFN0cmluZz4gbnVtVG9Xb3JkID0gbmV3IEhhc2hNYXA8PigpOwoKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICAgICAgICAgIFN0cmluZyB3b3JkID0gc2MubmV4dCgpOwogICAgICAgICAgICAgICAgd29yZFRvTnVtLnB1dCh3b3JkLCBpKTsKICAgICAgICAgICAgICAgIG51bVRvV29yZC5wdXQoaSwgd29yZCk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGludCBtID0gc2MubmV4dEludCgpOwoKICAgICAgICAgICAgTGlzdDxBcnJheUxpc3Q8SW50ZWdlcj4+IGFkaiA9IG5ldyBBcnJheUxpc3Q8PigpOwoKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIGFkai5hZGQobmV3IEFycmF5TGlzdDw+KCkpOwoKICAgICAgICAgICAgaW50W10gaW5kZWdyZWUgPSBuZXcgaW50WzEwMV07CgogICAgICAgICAgICBTdHJpbmdUb2tlbml6ZXIgc3RyaW5nVG9rZW5pemVyOwoKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgICAgICAgICAgICAgIFN0cmluZyB1ID0gc2MubmV4dCgpLCB2ID0gc2MubmV4dCgpOwogICAgICAgICAgICAgICAgYWRqLmdldCh3b3JkVG9OdW0uZ2V0KHUpKS5hZGQod29yZFRvTnVtLmdldCh2KSk7CiAgICAgICAgICAgICAgICBpbmRlZ3JlZVt3b3JkVG9OdW0uZ2V0KHYpXSsrOwogICAgICAgICAgICB9CgogICAgICAgICAgICBib29sZWFuW10gdmlzID0gbmV3IGJvb2xlYW5bMTAxXTsKICAgICAgICAgICAgQXJyYXlzLmZpbGwodmlzLCBmYWxzZSk7CgogICAgICAgICAgICBQcmlvcml0eVF1ZXVlPEludGVnZXI+IHF1ZXVlID0gbmV3IFByaW9yaXR5UXVldWUoKTsKCiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgICAgICAgICBpZiAoaW5kZWdyZWVbaV0gPT0gMCkgewogICAgICAgICAgICAgICAgICAgIHF1ZXVlLmFkZChpKTsKICAgICAgICAgICAgICAgICAgICB2aXNbaV0gPSB0cnVlOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfQoKICAgICAgICAgICAgTGlzdDxJbnRlZ2VyPiB0b3BvU29ydCA9IG5ldyBBcnJheUxpc3Q8PigpOwoKICAgICAgICAgICAgd2hpbGUgKCFxdWV1ZS5pc0VtcHR5KCkpIHsKICAgICAgICAgICAgICAgIGludCB1ID0gcXVldWUucG9sbCgpOwogICAgICAgICAgICAgICAgdG9wb1NvcnQuYWRkKHUpOwogICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBhZGouZ2V0KHUpLnNpemUoKTsgKytqKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKCF2aXNbYWRqLmdldCh1KS5nZXQoaildKSB7CgogICAgICAgICAgICAgICAgICAgICAgICBpZiAoLS1pbmRlZ3JlZVthZGouZ2V0KHUpLmdldChqKV0gPT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcXVldWUuYWRkKGFkai5nZXQodSkuZ2V0KGopKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZpc1thZGouZ2V0KHUpLmdldChqKV0gPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIFN0cmluZ0J1aWxkZXIgc2IgPSBuZXcgU3RyaW5nQnVpbGRlcigiIik7CgogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IHRvcG9Tb3J0LnNpemUoKTsgKytpKSB7CiAgICAgICAgICAgICAgICBpZiAoaSA9PSAwKQogICAgICAgICAgICAgICAgICAgIHNiLmFwcGVuZChudW1Ub1dvcmQuZ2V0KHRvcG9Tb3J0LmdldChpKSkpOwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIHNiLmFwcGVuZCgiICIgKyBudW1Ub1dvcmQuZ2V0KHRvcG9Tb3J0LmdldChpKSkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQ2FzZSAjIiArICh0ZXN0Q2FzZSsrKSArICI6IERpbGJlcnQgc2hvdWxkIGRyaW5rIGJldmVyYWdlcyBpbiB0aGlzIG9yZGVyOiAiICsgc2IudG9TdHJpbmcoKSArICIuIik7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigpOwoKICAgICAgICB9Cgl9Cn0=
stdin
OAphCmIKYwpkCmUKZgpzCnQKNgphIGUKYSBiCmMgZAplIGYKcyB0CmEgdAoKOApzCmEKYgplCmYKYwpkCnQKNgphIGUKYSBiCmMgZAplIGYKcyB0CmEgdAoKOAphCmIKYwpzCnQKZQpmCmQKNgphIGIKYSBlCmMgZAplIGYKcyB0CmEgdAo=
8
a
b
c
d
e
f
s
t
6
a e
a b
c d
e f
s t
a t
8
s
a
b
e
f
c
d
t
6
a e
a b
c d
e f
s t
a t
8
a
b
c
s
t
e
f
d
6
a b
a e
c d
e f
s t
a t