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.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	void run() throws IOException {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int W = sc.nextInt();
			int H = sc.nextInt();
			if (W == 0 && H == 0)
				break;
			char[][] map = new char[H][W];
			for (int i = 0; i < H; ++i) {
				map[i] = sc.next().toCharArray();
			}
			int Ax = -1, Ay = -1;
			int Qx = -1, Qy = -1;
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					if (map[i][j] == 'A') {
						Ay = i;
						Ax = j;
					} else if (map[i][j] == 'Q') {
						Qy = i;
						Qx = j;
					}
				}
			}
			int[][][] memo = new int[H * W][H * W][2];

			for (int q = 0; q < H * W; ++q) {
				if (!valid(q, map, H, W))
					continue;
				for (int a = 0; a < H * W; ++a) {
					if (!valid(a, map, H, W))
						continue;
					for (int t = 0; t < 2; ++t) {
						if (q == a) {
							memo[q][a][t] = -1;// Q?????????
						} else if (t == 0 && map[q / W][q % W] == 'E') {
							memo[q][a][t] = 1;// Q?????????
						}
					}
				}
			}
			int[] d = { 0, W, -W, 1, -1 };

			for (boolean update = true; update;) {
				update = false;
				for (int q = 0; q < H * W; ++q) {
					if (!valid(q, map, H, W))
						continue;
					for (int a = 0; a < H * W; ++a) {
						if (!valid(a, map, H, W))
							continue;
						for (int t = 0; t < 2; ++t) {
							if (memo[q][a][t] != 0) {
								continue;
							}
							int v = (t == 0 ? -999 : 999);
							for (int i = 0; i < 5; ++i) {
								int na = a, nq = q;
								if (t == 0)
									nq += d[i];
								else
									na += d[i];
								if ((t == 1 && !valid(a, d[i], map, H, W)) || (t == 0 && !valid(q, d[i], map, H, W)))
									continue;
								if (t == 0) {
									v = Math.max(v, memo[nq][na][t ^ 1]);
								} else {
									v = Math.min(v, memo[nq][na][t ^ 1]);
								}
							}
							if (v != 0) {
								memo[q][a][t] = v;
								update = true;
							}
						}
					}
				}

			}
			int Q = Qy * W + Qx;
			int A = Ay * W + Ax;
			if (memo[Q][A][0] == 0) {
				System.out.println("Queen can not escape and Army can not catch Queen.");
			} else if (memo[Q][A][0] == -1) {
				System.out.println("Army can catch Queen.");
			} else if (memo[Q][A][0] == 1) {
				System.out.println("Queen can escape.");
			}
		}

	}

	boolean valid(int a, int d, char[][] map, int H, int W) {
		if (!valid(a, map, H, W) || !valid(a + d, map, H, W)) {
			return false;
		}
		int h = a / W;
		int w = a % W;
		int nh = (a + d) / W;
		int nw = (a + d) % W;
		if (Math.abs(nh - h) + Math.abs(nw - w) <= 1) {
			return true;
		} else {
			return false;
		}
	}

	boolean valid(int a, char[][] map, int H, int W) {
		if (a < 0 || a >= H * W)
			return false;
		int h = a / W;
		int w = a % W;
		if (map[h][w] == '#')
			return false;
		return true;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}