import java.util.*; public class KarakuriDoll { static class State { int x, y, d, ID, count[] = new int[2]; boolean isGoal; State[] sw1 = new State[2], sw2[] = new State[2][11]; State(int X,int Y,int D){ x = X; y = Y; d = D; ID = (d << 14) | (y << 7) | x; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { W = sc.nextInt();H = sc.nextInt(); if(W + H == 0) break; char[][]km = new char[H][W]; int kx = -1, ky = -1, mx = -1, my = -1; for(int i = 0; i < H; i++){ String str = sc.next(); for(int j = 0; j < W; j++) switch(km[i][j] = str.charAt(j)){ case 'K':ky = i; kx = j; km[i][j] = '.'; break; case 'M':my = i; mx = j; km[i][j] = '.'; } } State[] dfa = bfs1(km,false,kx,ky,mx,my), nfa = bfs1(km,true,mx,my,kx,ky); System.out.println(dfa == null? "He cannot bring tea to his master.": nfa != null && bfs2(dfa[0], nfa)? "He can accomplish his mission.": "He cannot return to the kitchen."); } } static int H, W, mvX[]={0,-1,0,1}, mvY[]={-1,0,1,0}; static State[] bfs1(char[][]map,boolean flag,int kx,int ky,int mx,int my){ int kd = -1; boolean bringTea = false; State states[][][] = new State[H][W][4], start; for(int i = 0; i < 4; i++) if(map[ky + mvY[i]][kx + mvX[i]] == '.') kd = i; for(; map[ky + mvY[kd]][kx + mvX[kd]]=='.'; kx += mvX[kd])ky += mvY[kd]; Queue queue = new LinkedList(); queue.add(states[ky][kx][kd] = start = new State(kx,ky,kd)); start.isGoal = flag; while(!queue.isEmpty()){ State state = queue.poll(); int y = state.y, x = state.x, d = state.d; if(!flag && y == my && x == mx) state.isGoal = true; if(y == my && x == mx) bringTea = true; for(int i = 1; i < 4; i+=2) { int D = (d + i) % 4, X = x, Y = y; for(;map[Y + mvY[D]][X + mvX[D]] == '.';X += mvX[D])Y += mvY[D]; if(states[Y][X][D] == null) queue.add(states[Y][X][D] = new State(X,Y,D)); if(flag) states[Y][X][D].sw2[i/2][states[Y][X][D].count[i/2]++] = state; else state.sw1[i%3] = states[Y][X][D]; } } return bringTea? flag? states[my][mx]: new State[]{start}: null; } static boolean bfs2(State dfa, State[] nfa){ Queue queue = new LinkedList(); Set already = new HashSet(); for(State m : nfa) if(m != null && already.add((dfa.ID << 16) | m.ID)) queue.add(new State[]{dfa, m}); while(!queue.isEmpty()){ State[]km = queue.poll(); for(int i = 0; i < 2; i++) if(km[0].sw1[i] != null) for(State tmp : km[1].sw2[i]) if(tmp != null) if(km[0].sw1[i].isGoal && tmp.isGoal) return true; else if(already.add((km[0].sw1[i].ID << 16) | tmp.ID)) queue.add(new State[]{km[0].sw1[i], tmp}); } return false; } }