package com.company;
import java.io.*;
import java.util.*;
public class Main {
static int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
static char[][] block = {{'|', '+', '2', '3'}, {'|', '+', '1', '4'}, {'-', '+', '3', '4'}, {'-', '+', '1', '2'}};
static int[][] number = {{-1, 2, -1, 0}, {2, -1, -1, 1}, {3, -1, 1, -1}, {-1, 3, 0, -1}};
static char[][] arr;
static int[] M;
static int R, C;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
arr = new char[R][C];
for (int i = 0; i < R; i++) {
String s = br.readLine();
for (int j = 0; j < C; j++) {
arr[i][j] = s.charAt(j);
if (arr[i][j] == 'M') {
M = new int[]{i, j, 0};
}
}
}
outer:
for (int i = 0; i < 4; i++) {
int[] nextM = {d[i][0] + M[0], d[i][1] + M[1]};
if (nextM[0] >= 0 && nextM[1] >= 0 && nextM[0] < R && nextM[1] < C) {
for (int j = 0; j < 4; j++) {
if (arr[nextM[0]][nextM[1]] == block[i][j]) {
M[0] = nextM[0];
M[1] = nextM[1];
M[2] = i;
break outer;
}
}
}
}
find();
int blockR = M[0];
int blockC = M[1];
int direct = M[2];
for (int i = 0; i < block[direct].length; i++) {
M[0] = blockR;
M[1] = blockC;
M[2] = direct;
arr[blockR][blockC] = block[direct][i];
if (find()) {
System.out.println((blockR + 1) + " " + (blockC + 1) + " " + block[direct][i]);
break;
}
}
}
static boolean find() {
while (M[0] >= 0 && M[0] < R && M[1] >= 0 && M[1] < C && arr[M[0]][M[1]] != '.') {
int x = (arr[M[0]][M[1]] - '0') - 1;
if (arr[M[0]][M[1]] == 'Z') {
return true;
}
if (arr[M[0]][M[1]] == '+'
|| (arr[M[0]][M[1]] == '-' && (M[2] == 2 || M[2] == 3))
|| (arr[M[0]][M[1]] == '|' && (M[2] == 0 || M[2] == 1))) {
M[0] += d[M[2]][0];
M[1] += d[M[2]][1];
}
else if (x < 4 && x >= 0 && number[x][M[2]] >= 0) {
M[0] += d[number[x][M[2]]][0];
M[1] += d[number[x][M[2]]][1];
M[2] = number[x][M[2]];
} else {
return false;
}
}
return false;
}
}