#include<cstdio>
#define din1(a) scanf("%d",&a)
const int M = 33;
char imap[M][M];
int vis[M][M];
const int dr[] = { -1,0,1,0 }; // U L D R
const int dc[] = { 0,-1,0,1 };
const int flow[] = { 1 << 0, 1 << 1, 1 << 2, 1 << 3 }; // ULDR
struct pipe {
char block;
int flow_d;
pipe() :block(0), flow_d(0) {}
void set_pipe(char ib, int iflow) {
block = ib;
flow_d = iflow;
}
};
const int N = 9;
pipe bn[9];
const char block_c[] = { '|', '-', '+', '1', '2', '3', '4', 'M', 'Z' };
const char block_f[] = {
flow[0] | flow[2],
flow[1] | flow[3],
flow[0] | flow[1] | flow[2] | flow[3],
flow[2] | flow[3],
flow[0] | flow[3],
flow[0] | flow[1],
flow[1] | flow[2],
flow[0] | flow[1] | flow[2] | flow[3],
flow[0] | flow[1] | flow[2] | flow[3],
};
void init() {
for (int i = 0; i < 9; i++) {
bn[i].set_pipe(block_c[i], block_f[i]);
}
}
int main() {
int row, col;
din1(row);
din1(col);
init();
for (int r = 0; r < row; r++) {
scanf("%s", imap[r]);
} // input
for (int r = 0; r < row; r++) {
for (int c = 0; c < col; c++) {
if (imap[r][c] == '.') continue;
if (imap[r][c] == 'M' || imap[r][c] == 'Z') continue;
pipe here;
here.set_pipe(imap[r][c], 0);
for (int i = 0; i < N; i++) {
if (here.block == bn[i].block) {
here.flow_d = bn[i].flow_d;
break;
}
}
for (int i = 0; i < 4; i++) {
int tr = r + dr[i];
int tc = c + dc[i];
if (tr < 0 || tc < 0 || row <= tr || col <= tc) continue; // range over
if ((here.flow_d & flow[i]) != flow[i]) continue; // impossible i-th dir flow
int there_flow = flow[(i + 2) % 4];
vis[tr][tc] += there_flow;
}
}
} // flow
for (int r = 0; r < row; r++) {
for (int c = 0; c < col; c++) {
if (imap[r][c] != '.') continue;
if (vis[r][c] == 0) continue;
for (int i = 0; i < 4; i++) {
int tr = r + dr[i];
int tc = c + dc[i];
if (tr < 0 || tc < 0 || row <= tr || col <= tc) continue; // range over
if (imap[tr][tc] == 'M' || imap[tr][tc] == 'Z') {
int there_flow = flow[i];
vis[r][c] = vis[r][c] | there_flow;
}
}
for (int i = 0; i < 7; i++) {
if (vis[r][c] == bn[i].flow_d) {
printf("%d %d %c\n", r + 1, c + 1, bn[i].block);
return 0;
}
}
}
}
for (int r = 0; r < row; r++) {
for (int c = 0; c < col; c++) {
if (imap[r][c] != '.') continue;
//if (vis[r][c] == 0) continue;
for (int i = 0; i < 4; i++) {
int tr = r + dr[i];
int tc = c + dc[i];
if (tr < 0 || tc < 0 || row <= tr || col <= tc) continue; // range over
if (imap[tr][tc] == 'M' || imap[tr][tc] == 'Z') {
int there_flow = flow[i];
vis[r][c] = vis[r][c] | there_flow;
}
}
for (int i = 0; i < 7; i++) {
if (vis[r][c] == bn[i].flow_d) {
printf("%d %d %c\n", r + 1, c + 1, bn[i].block);
return 0;
}
}
}
}
return 0;
}
/*
@test case
2 4
M14Z
232.
2 4
M.-Z
23..
2 4
M.-Z
....
6 6
1--M.Z
24..1.
.|.13.
.|.24.
.|1-3.
.23...
*/