Problem: A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into the entrance.

Your task is to write a program to determine whether the queen can escape or will be caught by the army.

Here is detailed description.

* The palace can be considered as grid squares.
* The queen and the army move alternately. The queen moves first.
* At each of their turns, they either move to an adjacent cell or stay at the same cell.
* Each of them must follow the optimal strategy.
* If the queen and the army are at the same cell, the queen will be caught by the army immediately.
* If the queen is at any of exit cells alone after the army’s turn, the queen can escape from the army.
* There may be cases in which the queen cannot escape but won’t be caught by the army forever, under their optimal strategies.

Hint

On the first sample input, the queen can move to exit cells, but either way the queen will be caught at the next army’s turn. So the optimal strategy for the queen is staying at the same cell. Then the army can move to exit cells as well, but again either way the army will miss the queen from the other exit. So the optimal strategy for the army is also staying at the same cell. Thus the queen cannot escape but won’t be caught.



Input

The input consists of multiple datasets. Each dataset describes a map of the palace. The first line of the input contains two integers W (1 ≤ W ≤ 30) and H (1 ≤ H ≤ 30), which indicate the width and height of the palace. The following H lines, each of which contains W characters, denote the map of the palace. "Q" indicates the queen, "A" the army,"E" an exit,"#" a wall and "." a floor.

The map contains exactly one "Q", exactly one "A" and at least one "E". You can assume both the queen and the army can reach all the exits.

The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.

Output

For each dataset, output "Queen can escape.", "Army can catch Queen." or "Queen can not escape and Army can not catch Queen." in a line.

Examples

Input

2 2
QE
EA
3 1
QAE
3 1
AQE
5 5
..E..
.###.
A###Q
.###.
..E..
5 1
A.E.Q
5 5
A....
####.
..E..
.####
....Q
0 0


Output

Queen can not escape and Army can not catch Queen.
Army can catch Queen.
Queen can escape.
Queen can not escape and Army can not catch Queen.
Army can catch Queen.
Army can catch Queen.


Input

2 2
QE
EA
3 1
QAE
3 1
AQE
5 5
..E..
.###.
A###Q
.###.
..E..
5 1
A.E.Q
5 5
A....
.
..E..
.####
....Q
0 0


Output

Queen can not escape and Army can not catch Queen.
Army can catch Queen.
Queen can escape.
Queen can not escape and Army can not catch Queen.
Army can catch Queen.
Army can catch Queen.

Solution (in JAVA):

Solution:

import java.util.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {
    int INF = 2 << 28;
    
    int w, h;
    boolean[][] map;
    ArrayList<P> trgPs;
    int qsx, qsy, asx, asy;
    
    int[][][][][] mem;

    
    void run() {
        Scanner sc = new Scanner(System.in);
        
        for (;;) {
            w = sc.nextInt(); h = sc.nextInt();
            if ((w|h) == 0) break;
            map = new boolean[h + 2][w + 2];
            trgPs = new ArrayList<P>();
            
            for (int i = 1; i <= h; i++) {
                String l = sc.next();
                for (int j = 1; j <= w; j++) {
                    switch (l.charAt(j - 1)) {
                    case '.': map[i][j] = true;  break;
                    case '#': map[i][j] = false; break;
                    case 'Q': map[i][j] = true;  qsx = j; qsy = i; break;
                    case 'A': map[i][j] = true;  asx = j; asy = i; break;
                    case 'E': map[i][j] = true;  trgPs.add(new P(j, i));
                    }
                }
            }
            
            mem = new int[2][w + 2][h + 2][w + 2][h + 2];
            
            for (P p : trgPs) {
                for (int x = 1; x <= w; x++) for (int y = 1; y <= h; y++) {
                    mem[0][p.x][p.y][x][y] = 1;
                }
            }
            
            for (int x = 1; x <= w; x++) for (int y = 1; y <= h; y++) {
                mem[0][x][y][x][y] = -1;
            }
            
            boolean update = true;
            int x = 1;
            while (update) {
                update = false;
                for (int qx = 1; qx <= w; qx++) for (int qy = 1; qy <= h; qy++) if (map[qy][qx]) {
                    for (int ax = 1; ax <= w; ax++) for (int ay = 1; ay <= h; ay++) if (map[ay][ax]) {
                        update |= update(qx, qy, ax, ay, x);
                    }
                }
//                debug(x, update);
                x = 1 - x;
                for (int[][][] a : mem[x]) for (int[][] b : a) for (int[] c : b) fill(c, 0);
            }
            
            
            
            switch (mem[1-x][qsx][qsy][asx][asy]) {
            case 1:
                System.out.println("Queen can escape.");
                break;
            case 0:
                System.out.println("Queen can not escape and Army can not catch Queen.");
                break;
            case -1:
                System.out.println("Army can catch Queen.");
                break;
            }
        }
    }
    
    int[] dx = {-1,0,1,0,0};
    int[] dy = {0,-1,0,1,0};
    boolean update(int qx, int qy, int ax, int ay, int t) {
        if (mem[1-t][qx][qy][ax][ay] != 0) {
            mem[t][qx][qy][ax][ay] = mem[1-t][qx][qy][ax][ay];
            return false;
        }
        
        for (int i = 0; i < 5; i++) if (map[qy+dy[i]][qx+dx[i]]) {
            boolean flg = true;
            for (int j = 0; j < 5; j++) if (map[ay+dy[j]][ax+dx[j]]) 
                flg &= mem[1-t][qx+dx[i]][qy+dy[i]][ax+dx[j]][ay+dy[j]] > 0;
            if (flg) {
                mem[t][qx][qy][ax][ay] = 1;
                return true;
            }
        }
        
        boolean flg = true;
        for (int i = 0; i < 5; i++) if (map[qy+dy[i]][qx+dx[i]]) {
            boolean tmp = false;
            for (int j = 0; j < 5; j++) if (map[ay+dy[j]][ax+dx[j]])
                tmp |= mem[1-t][qx+dx[i]][qy+dy[i]][ax+dx[j]][ay+dy[j]] < 0;
            flg &= tmp;
        }
        if (flg) {
            mem[t][qx][qy][ax][ay] = -1;
            return true;
        }
        
        return false;
    }
    
    class P {
        int x, y;
        P(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    
    void debug(Object...os) {
        System.err.println(deepToString(os));
    }
    
    public static void main(String[] args) {
        new Main().run();
    }
}