#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int max( int a, int b)
{
if ( a > b) return a;
return b;
}
int min( int a, int b)
{
if ( a < b) return a;
return b;
}
void swap( int * a, int * b)
{
int tmp = * a;
* a = * b;
* b = tmp;
}
int dx[ ] = { 0 , 0 , 1 , - 1 , 1 , - 1 , 1 , - 1 } , dy[ ] = { 1 , - 1 , 0 , 0 , 1 , 1 , - 1 , - 1 } ;
char a[ 200 ] [ 200 ] , s[ 100 ] [ 100 ] , input[ 100 ] ; int n, m;
struct Pos{
int x, y, dir_x, dir_y;
} pos[ 100 ] ;
void find( int sx, int sy, int i)
{
for ( int d = 0 ; d < 8 ; ++ d) {
int nx = sx, ny = sy, j = 0 ; bool check = true ;
while ( nx
> 0 && ny
> 0 && nx
<= n
&& ny
<= m
&& j
< strlen ( s
[ i
] ) ) { if ( a[ nx] [ ny] != s[ i] [ j] ) { check = false ; break ; }
nx += dx[ d] ; ny += dy[ d] ;
++ j;
}
if ( check
&& j
== strlen ( s
[ i
] ) ) { pos[ i] = ( struct Pos) { sx, sy, dx[ d] , dy[ d] } ;
return ;
}
}
}
int main( )
{
}
for ( int i = 1 ; i <= n; ++ i) {
fgets ( input
, sizeof ( input
) , stdin
) ; input
[ strcspn ( input
, "\n " ) ] = '\0 ' ; for ( int j
= 0 , k
= 0 ; j
< strlen ( input
) ; ++ j
) if ( input
[ j
] != ' ' ) a
[ i
] [ ++ k
] = input
[ j
] ; }
for ( int i = 1 ; i < 100 ; ++ i) pos[ i] = ( struct Pos) { 0 , 0 , 0 , 0 } ;
int num = 0 ;
while ( scanf ( "%s" , s
[ ++ num
] ) ) { s
[ num
] [ strcspn ( s
[ num
] , "\n " ) ] = '\0 ' ; if ( s[ num] [ 0 ] == '#' ) break ;
}
-- num;
for ( int i = 1 ; i <= n; ++ i) for ( int j = 1 ; j <= m; ++ j) for ( int k = 1 ; k <= num; ++ k)
find( i, j, k) ;
for ( int i = 1 ; i <= num; ++ i) {
if ( ! pos
[ i
] .
x ) printf ( "%s %d\n " , s
[ i
] , - 1 ) ; else printf ( "%s %d %d %d %d\n " , s
[ i
] , pos
[ i
] .
x - 1 , pos
[ i
] .
y - 1 , pos
[ i
] .
dir_x , pos
[ i
] .
dir_y ) ; }
// printf("-1");
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGJvb2wuaD4KCmludCBtYXgoaW50IGEsIGludCBiKQp7CiAgaWYoYSA+IGIpIHJldHVybiBhOwogIHJldHVybiBiOwp9CgppbnQgbWluKGludCBhLCBpbnQgYikKewogIGlmKGEgPCBiKSByZXR1cm4gYTsKICByZXR1cm4gYjsKfQoKdm9pZCBzd2FwKGludCAqYSwgaW50ICpiKQp7CiAgaW50IHRtcCA9ICphOwogICphID0gKmI7CiAgKmIgPSB0bXA7Cn0KCmludCBkeFtdID0gezAsIDAsIDEsIC0xLCAxLCAtMSwgMSwgLTF9LCBkeVtdID0gezEsIC0xLCAwLCAwLCAxLCAxLCAtMSwgLTF9OwoKY2hhciBhWzIwMF1bMjAwXSwgc1sxMDBdWzEwMF0sIGlucHV0WzEwMF07IGludCBuLCBtOwoKCnN0cnVjdCBQb3N7CiAgaW50IHgsIHksIGRpcl94LCBkaXJfeTsKfXBvc1sxMDBdOwoKdm9pZCBmaW5kKGludCBzeCwgaW50IHN5LCBpbnQgaSkKewogIGZvcihpbnQgZCA9IDA7IGQgPCA4OyArKyBkKXsKICAgIGludCBueCA9IHN4LCBueSA9IHN5LCBqID0gMDsgYm9vbCBjaGVjayA9IHRydWU7CiAgICB3aGlsZShueCA+IDAgJiYgbnkgPiAwICYmIG54IDw9IG4gJiYgbnkgPD0gbSAmJiBqIDwgc3RybGVuKHNbaV0pKXsKICAgICAgaWYoYVtueF1bbnldICE9IHNbaV1bal0pIHsgY2hlY2sgPSBmYWxzZTsgYnJlYWs7IH0KICAgICAgbnggKz0gZHhbZF07IG55ICs9IGR5W2RdOwogICAgICArKyBq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