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>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;

class graph_bridge{
public:
	static const int MAX=905;
	vector<int> G[MAX];
	bool visited[MAX];
	int prenum[MAX],parent[MAX],lowest[MAX],timer;
	set<P> bridge;
	int cmp[MAX];

	void dfs(int v,int prev){
		prenum[v]=lowest[v]=timer;
		timer++;
		visited[v]=true;
		int next;
		for(int i=0;i<G[v].size();i++){
			next=G[v][i];
			if(!visited[next]){
				parent[next]=v;
				dfs(next,v);
				lowest[v]=min(lowest[v],lowest[next]);
				if(prenum[v]<lowest[G[v][i]])bridge.insert(P(min(v,G[v][i]),max(v,G[v][i])));
			}else if(next!=prev){
				lowest[v]=min(lowest[v],prenum[next]);
			}
		}
	}

	void dfs2(int v,int k){
		cmp[v]=k;
		for(int i=0;i<G[v].size();i++){
			int nv=G[v][i];
			if(cmp[nv]>=0)continue;
			if(bridge.find(P(min(v,nv),max(v,nv)))==bridge.end()){
				dfs2(nv,k);
			}
		}
	}

	int construct_TwoEdgeConnectedComponent(int N){
		for(int i=0;i<N;i++){
			visited[i]=false;
		}
		timer=1;
		bridge.clear();
		for(int i=0;i<N;i++){
			if(!visited[i]){
				dfs(i,-1);
			}
		}
		memset(cmp,-1,sizeof(cmp));
		int k=0;
		for(int i=0;i<N;i++){
			if(cmp[i]==-1){
				dfs2(i,k);
				k++;
			}
		}
		return k;
	}
};

graph_bridge b;

int w,h;
int fie[31][31];
bool flag[31][31][31][31];
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int dist[2][31][31];
int cnt[905];
P q,a;

void bfs(){
	memset(dist,-1,sizeof(dist));
	for(int i=0;i<2;i++){
		queue<P> que;
		if(i==0){
			que.push(q);
			dist[i][q.first][q.second]=0;
		}else{
			que.push(a);
			dist[i][a.first][a.second]=0;
		}
		while(que.size()){
			P p=que.front();
			que.pop();
			for(int j=0;j<4;j++){
				int nx=p.second+dx[j];
				int ny=p.first+dy[j];
				if(nx<0 || ny<0 || nx>=w || ny>=h)continue;
				if(fie[ny][nx]==-1)continue;
				if(dist[i][ny][nx]==-1){
					dist[i][ny][nx]=dist[i][p.first][p.second]+1;
					que.push(P(ny,nx));
				}
			}
		}
	}
}

void solve(){
	memset(fie,0,sizeof(fie));
	memset(flag,false,sizeof(flag));
	memset(cnt,0,sizeof(cnt));
	for(int i=0;i<h;i++){
		string str;
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='#'){
				fie[i][j]=-1;
			}
			if(str[j]=='E'){
				fie[i][j]=1;
			}
			if(str[j]=='Q'){
				q=P(i,j);
			}
			if(str[j]=='A'){
				a=P(i,j);
			}
		}
	}
	queue<PP> que;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fie[i][j]==1){
				for(int k=0;k<h;k++){
					for(int l=0;l<w;l++){
						if(k==i && l==j)continue;
						if(fie[k][l]==-1)continue;
						flag[i][j][k][l]=true;
						que.push(PP(P(i,j),P(k,l)));
					}
				}
			}
		}
	}
	while(que.size()){
		PP p=que.front();
		que.pop();
		P pq=p.first,pa=p.second;
		//printf("%d %d %d %d\n",pq.second,pq.first,pa.second,pa.first);
		for(int i=0;i<4;i++){
			int nx=pq.second+dx[i];
			int ny=pq.first+dy[i];
			//printf("%d %d\n",nx,ny);
			if(nx<0 || ny<0 || nx>=w || ny>=h)continue;
			if(fie[ny][nx]==-1)continue;
			for(int j=0;j<5;j++){
				int n2x=pa.second+dx[j];
				int n2y=pa.first+dy[j];
				//printf("n2x %d %d\n",n2x,n2y);
				if(n2x<0 || n2y<0 || n2x>=w || n2y>=h)continue;
				if(fie[n2y][n2x]==-1)continue;
				if(nx==n2x && ny==n2y)continue;
				if(flag[ny][nx][n2y][n2x])continue;
				bool fo=true;
				for(int k=0;k<5;k++){
					int n3x=n2x+dx[k];
					int n3y=n2y+dy[k];
					//printf("check %d %d\n",n3x,n3y);
					if(n3x<0 || n3y<0 || n3x>=w || n3y>=h)continue;
					if(fie[n3y][n3x]==-1)continue;
					if(!flag[pq.first][pq.second][n3y][n3x])fo=false;
				}
				if(fo){
					//printf("ok %d %d %d %d\n",nx,ny,n2x,n2y);
					flag[ny][nx][n2y][n2x]=true;
					que.push(PP(P(ny,nx),P(n2y,n2x)));
				}
			}
		}
	}
	if(flag[q.first][q.second][a.first][a.second]){
		printf("Queen can escape.\n");
		return;
	}
	bfs();
	for(int i=0;i<h*w;i++){
		b.G[i].clear();
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fie[i][j]>=0){
				for(int k=0;k<4;k++){
					int nx=j+dx[k];
					int ny=i+dy[k];
					if(nx<0 || nx>=w || ny<0 || ny>=h)continue;
					if(fie[ny][nx]==-1)continue;
					b.G[i*w+j].push_back(ny*w+nx);
				}
			}
		}
	}
	int sz=b.construct_TwoEdgeConnectedComponent(h*w);
	for(int i=0;i<h*w;i++){
		cnt[b.cmp[i]]++;
	}
	bool draw=false;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			//printf("%d %d %d\n",i,j,cnt[b.cmp[i*w+j]]);
			if(cnt[b.cmp[i*w+j]]>1 && dist[0][i][j]>=0 && (dist[0][i][j]<dist[1][i][j] || dist[1][i][j]==-1)){
				draw=true;
			}
		}
	}
	if(dist[1][q.first][q.second]==-1)draw=true;
	printf("%s\n",draw?"Queen can not escape and Army can not catch Queen.":"Army can catch Queen.");
	return;
}

int main(void){
	while(1){
		scanf("%d%d",&w,&h);
		if(w==0 && h==0)break;
		solve();
	}
}