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 CPP):

Solution:
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

typedef vector<vector<int>> graph;

constexpr int MAX_N = 900;

enum {ESCAPE, LOOP, CATCH};
enum {Q, A, NUM};

const string message[3] = {
	"Queen can escape.",
	"Queen can not escape and Army can not catch Queen.",
	"Army can catch Queen.",
};

int dp[MAX_N][MAX_N][NUM];

inline int get_index(int x, int y, int w) {
	return x + y * w;
}

inline void add_edge(int a, int b, graph &G) {
	G[a].emplace_back(b);
	G[b].emplace_back(a);
}

inline string solve(int q, int a, const vector<int> &g, const graph &G) {
	const int n = G.size();
	for(int v = 0; v < n; ++v) {
		for(int u = 0; u < n; ++u) {
			dp[v][u][Q] = dp[v][u][A] = LOOP;
		}
	}

	for(int v = 0; v < n; ++v) {
		dp[v][v][Q] = dp[v][v][A] = CATCH;
	}

	for(const auto &e : g) {
		for(int v = 0; v < n; ++v) {
			if(e != v) dp[e][v][Q] = ESCAPE;
		}
	}

	while(true) {
		bool update = false;

		for(int v = 0; v < n; ++v) {
			for(int u = 0; u < n; ++u) {
				if(v == u) continue;

				// queen turn
				if(dp[v][u][Q] != ESCAPE) {
					const int prev = dp[v][u][Q];
					dp[v][u][Q] = CATCH;
					for(const auto &to : G[v]) {
						chmin(dp[v][u][Q], dp[to][u][A]);
					}
					if(dp[v][u][Q] != prev) update = true;
				}

				// army turn
				{
					const int prev = dp[v][u][A];
					dp[v][u][A] = ESCAPE;
					for(const auto &to : G[u]) {
						chmax(dp[v][u][A], dp[v][to][Q]);
					}
					if(dp[v][u][A] != prev) update = true;
				}
			}
		}

		if(!update) break;
	}

	return message[dp[q][a][Q]];
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int w, h; cin >> w >> h && w;) {
		vector<string> field(h);
		for(auto &e : field) cin >> e;

		int next_label = 0;
		vector<vector<int>> label(h, vector<int>(w, -1));
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				if(field[i][j] != '#') label[i][j] = next_label++;
			}
		}

		int q, a;
		vector<int> g;

		graph G(next_label);

		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				if(field[i][j] == '#') continue;

				const int v = label[i][j];

				switch(field[i][j]) {
				case 'Q': q = v; break;
				case 'A': a = v; break;
				case 'E': g.emplace_back(v); break;
				}

				add_edge(v, v, G);

				if(i < h - 1) {
					if(field[i + 1][j] != '#') {
						add_edge(v, label[i + 1][j], G);
					}
				}

				if(j < w - 1) {
					if(field[i][j + 1] != '#') {
						add_edge(v, label[i][j + 1], G);
					}
				}
			}
		}

		cout << solve(q, a, g, G) << endl;
	}

	return EXIT_SUCCESS;
}