def counter( string ) :
x= string .count ( 'X' )
o= string .count ( 'O' )
d= string .count ( '.' )
t= string .count ( 'T' )
return ( x, o, t, d)
def win( tupa) :
if ( ( tupa[ 0 ] == 3 and tupa[ 2 ] == 1 ) or tupa[ 0 ] == 4 ) :
print 'Case #' +str ( i) +': X won'
return True
elif ( ( tupa[ 1 ] == 3 and tupa[ 2 ] == 1 ) or tupa[ 1 ] == 4 ) :
print 'Case #' +str ( i) +': O won'
return True
return False
t= input ( )
for i in range ( 1 , t+1 ) :
a= [ [ ] , [ ] , [ ] , [ ] ]
status= True
flag= False
a[ 0 ] = raw_input ( )
if ( len ( a[ 0 ] ) == 0 ) :
a[ 0 ] = raw_input ( )
a[ 1 ] = raw_input ( )
a[ 2 ] = raw_input ( )
a[ 3 ] = raw_input ( )
for p in range ( 0 , 4 ) : #horizontal case
tup= counter( a[ p] )
if ( tup[ 3 ] > 0 ) :
flag= True
if ( win( tup) ) :
status= False
break
if ( not status) :
continue
for p in range ( 0 , 4 ) :
tup= counter( a[ 0 ] [ p] +a[ 1 ] [ p] +a[ 2 ] [ p] +a[ 3 ] [ p] )
if ( tup[ 3 ] > 0 ) :
flag= True
if ( win( counter( a[ 0 ] [ p] +a[ 1 ] [ p] +a[ 2 ] [ p] +a[ 3 ] [ p] ) ) ) :
status= False
break
if ( not status) :
continue
if ( win( counter( a[ 0 ] [ 0 ] +a[ 1 ] [ 1 ] +a[ 2 ] [ 2 ] +a[ 3 ] [ 3 ] ) ) ) : #diagonal
status= False
continue
if ( win( counter( a[ 3 ] [ 0 ] +a[ 2 ] [ 1 ] +a[ 1 ] [ 2 ] +a[ 0 ] [ 3 ] ) ) ) :
status= False
continue
if ( status and flag) :
print 'Case #' +str ( i) +': Game not completed'
continue
print 'Case #' +str ( i) +': Draw'
ZGVmIGNvdW50ZXIoc3RyaW5nKToKICAgIHg9c3RyaW5nLmNvdW50KCdYJykKICAgIG89c3RyaW5nLmNvdW50KCdPJykKICAgIGQ9c3RyaW5nLmNvdW50KCcuJykKICAgIHQ9c3RyaW5nLmNvdW50KCdUJykKICAgIHJldHVybiAoeCxvLHQsZCkKCmRlZiB3aW4odHVwYSk6CiAgICBpZigodHVwYVswXT09MyBhbmQgdHVwYVsyXT09MSkgb3IgdHVwYVswXT09NCk6CiAgICAgICAgcHJpbnQgJ0Nhc2UgIycrc3RyKGkpKyc6IFggd29uJwogICAgICAgIHJldHVybiBUcnVlCiAgICBlbGlmKCh0dXBhWzFdPT0zIGFuZCB0dXBhWzJdPT0xKW9yIHR1cGFbMV0gPT00KToKICAgICAgICBwcmludCAnQ2FzZSAjJytzdHIoaSkrJzogTyB3b24nCiAgICAgICAgcmV0dXJuIFRydWUKICAgIHJldHVybiBGYWxzZQogICAgICAgICAgICAgICAgCnQ9aW5wdXQoKQpmb3IgaSBpbiByYW5nZSgxLHQrMSk6CiAgICBhPVtbXSxbXSxbXSxbXV0KICAgIHN0YXR1cz1UcnVlCiAgICBmbGFnPUZhbHNlCiAgICBhWzBdPXJhd19pbnB1dCgpCiAgICBpZihsZW4oYVswXSk9PTApOgogICAgICAgIGFbMF09cmF3X2lucHV0KCkKICAgIGFbMV09cmF3X2lucHV0KCkKICAgIGFbMl09cmF3X2lucHV0KCkKICAgIGFbM109cmF3X2lucHV0KCkKCiAgICBmb3IgcCBpbiByYW5nZSgwLDQpOiAgICAgICAgICAgICNob3Jpem9udGFsIGNhc2UKICAgICAgICB0dXA9Y291bnRlcihhW3BdKQogICAgICAgIGlmKHR1cFszXT4wKToKICAgICAgICAgICAgZmxhZz1UcnVlCiAgICAgICAgaWYod2luKHR1cCkpOgogICAgICAgICAgICBzdGF0dXM9RmFsc2UKICAgICAgICAgICAgYnJlYWsKICAgIGlmKG5vdCBzdGF0dXMpOgogICAgICAgICAgICBjb250aW51ZQoKICAgIGZvciBwIGluIHJhbmdlKDAsNCk6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICB0dXA9Y291bnRlcihhWzBdW3BdK2FbMV1bcF0rYVsyXVtwXSthWzNdW3BdKQogICAgICAgIGlmKHR1cFszXT4wKToKICAgICAgICAgICAgZmxhZz1UcnVlCiAgICAgICAgaWYoIHdpbihjb3VudGVyKGFbMF1bcF0rYVsxXVtwXSthWzJdW3BdK2FbM11bcF0pKSk6CiAgICAgICAgICAgIHN0YXR1cz1GYWxzZQogICAgICAgICAgICBicmVhawogICAgaWYobm90IHN0YXR1cyk6CiAgICAgICAgICAgIGNvbnRpbnVlCgogICAgaWYod2luKGNvdW50ZXIoYVswXVswXSthWzFdWzFdK2FbMl1bMl0rYVszXVszXSkpKTogICAgICAgICAgI2RpYWdvbmFsCiAgICAgICAgc3RhdHVzPUZhbHNlCiAgICAgICAgY29udGludWUKICAgIGlmKHdpbihjb3VudGVyKGFbM11bMF0rYVsyXVsxXSthWzFdWzJdK2FbMF1bM10pKSk6CiAgICAgICAgc3RhdHVzPUZhbHNlCiAgICAgICAgY29udGludWUKICAgIAogICAgaWYoc3RhdHVzIGFuZCBmbGFnKTogICAKICAgICAgICBwcmludCAnQ2FzZSAjJytzdHIoaSkrJzogR2FtZSBub3QgY29tcGxldGVkJwogICAgICAgIGNvbnRpbnVlCiAgICBwcmludCAnQ2FzZSAjJytzdHIoaSkrJzogRHJhdyc=
stdin
NgpYIFggWCBUCi4gLiAuIC4KTyBPIC4gLgouIC4gLiAuCgpYIE8gWCBUClggWCBPIE8KTyBYIE8gWApYIFggTyBPCgpYIE8gWCAuCk8gWCAuIC4KLiAuIC4gLgouIC4gLiAuCgpPIE8gWCBYCk8gWCBYIFgKTyBYIC4gVApPIC4gLiBPCgpYIFggWCBPCi4gLiBPIC4KLiBPIC4gLgpUIC4gLiAuCgpPIFggWCBYClggTyAuIC4KLiAuIE8gLgouIC4gLiBP
6
X X X T
. . . .
O O . .
. . . .
X O X T
X X O O
O X O X
X X O O
X O X .
O X . .
. . . .
. . . .
O O X X
O X X X
O X . T
O . . O
X X X O
. . O .
. O . .
T . . .
O X X X
X O . .
. . O .
. . . O