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 <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
//[const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

int dp[2][33][33][33][33]; //turn, x_queen, y_queen, x_army, y_army
int h, w;
vs fld;

typedef tuple<int, int, int, int, int> state;

void init()
{
	fld.clear(); fld.resize(h);
	MS(dp, 0);
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	while (cin >> w >> h, h)
	{
		init();
		REP(i, h) cin >> fld[i];
		pii army, queen;
		set<pii> exit;
		REP(i, h)REP(j, w)
		{
			if (fld[i][j] == '#') continue;
			if (fld[i][j] == 'Q') queen = pii(i, j);
			if (fld[i][j] == 'A') army = pii(i, j);
			if (fld[i][j] == 'E') exit.emplace(i, j);
			fld[i][j] = '.';
		}
		vector<state> updates;
		for (auto i : exit)REP(ax, h)REP(ay, w)
		{
			int qx = i.first, qy = i.second;
			dp[0][qx][qy][ax][ay] = 1;
			updates.push_back(state(0, qx, qy, ax, ay));
		}
		REP(i, h)REP(j, w)
		{
			if (fld[i][j] == '#') continue;
			dp[0][i][j][i][j] = -1;
			updates.push_back(state(0, i, j, i, j));
		}
		REP(i, 2)REP(qx, h)REP(qy, w)REP(ax, h)REP(ay, w) updates.push_back(state(i, qx, qy, ax, ay));
		while (!updates.empty())
		{
			vector<state> nexts;
			for (auto tmp : updates)
			//REP(i, 2)REP(qx, h)REP(qy, w)REP(ax, h)REP(ay, w)
			{
				int i, qx, qy, ax, ay;
				tie(i, qx, qy, ax, ay) = tmp;
				if (!valid(qx, qy, h, w) || !valid(ax, ay, h, w) || dp[i][qx][qy][ax][ay] != 0) continue;
				if (i == 0)
				{
					set<int> st;
					st.insert(dp[1][qx][qy][ax][ay]);
					REP(j, 4)
					{
						int nx = qx + dx[j], ny = qy + dy[j];
						if (!valid(nx, ny, h, w) || fld[nx][ny] == '#') continue;
						st.insert(dp[1][nx][ny][ax][ay]);
					}
					if (st.size() == 1 && *st.begin() == -1)
					{
						dp[i][qx][qy][ax][ay] = -1;
					}
					else if (st.count(1))
					{
						dp[i][qx][qy][ax][ay] = 1;
					}
				}
				else
				{
					set<int> st;
					st.insert(dp[0][qx][qy][ax][ay]);
					REP(j, 4)
					{
						int nx = ax + dx[j], ny = ay + dy[j];
						if (!valid(nx, ny, h, w) || fld[nx][ny] == '#') continue;
						st.insert(dp[0][qx][qy][nx][ny]);
					}
					if (st.size() == 1 && *st.begin() == 1)
					{
						dp[i][qx][qy][ax][ay] = 1;
					}
					else if (st.count(-1))
					{
						dp[i][qx][qy][ax][ay] = -1;
					}
				}
				if (dp[i][qx][qy][ax][ay] != 0)
				{
					if (dp[1 - i][qx][qy][ax][ay] == 0)
					{
						nexts.push_back(state(1 - i, qx, qy, ax, ay));
					}
					REP(i, 2)REP(j, 4)REP(k, 4)
					{
						if (!valid(qx + dx[j], qy + dy[j], h, w) || !valid(ax + dx[k], ay + dy[k], h, w) || dp[i][qx + dx[j]][qy + dy[j]][ax + dx[k]][ay + dy[k]] != 0) continue;
						nexts.push_back(state(i, qx + dx[j], qy + dy[j], ax + dx[k], ay + dy[k]));
					}
				}
			}
			sort(ALL(updates));
			updates.erase(unique(ALL(updates)), updates.end());
			updates = nexts;
		}
		

		int ans = dp[0][queen.first][queen.second][army.first][army.second];
		if (ans == 1) cout << "Queen can escape." << endl;
		else if (ans == 0) cout << "Queen can not escape and Army can not catch Queen." << endl;
		else cout << "Army can catch Queen." << endl;
	}

	return 0;
}