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;
using Int = long long;
Int dp[2][33][33][33][33];
Int cnt[2][33][33][33][33];
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int w,h;
  while(cin>>w>>h,w){
    vector<string> s(h);
    for(Int i=0;i<h;i++) cin>>s[i];
    memset(dp,-1,sizeof(dp));
    memset(cnt,0,sizeof(cnt));
    {
      using T = tuple<Int, Int, Int, Int, Int>;
      queue<T> q;
      Int dy[]={0,0,1,-1,0};
      Int dx[]={1,-1,0,0,0};
      auto in=[&](Int y,Int x){
	return 0<=y&&y<h&&0<=x&&x<w;
      };
      
      for(Int qy=0;qy<h;qy++){
	for(Int qx=0;qx<w;qx++){
	  if(s[qy][qx]=='#') continue;
	  for(Int ay=0;ay<h;ay++){
	    for(Int ax=0;ax<w;ax++){
	      if(s[ay][ax]=='#') continue;
	      // t == 0	      
	      {		
		if(s[qy][qx]=='E'&&!(qy==ay&&qx==ax)){
		  dp[0][qy][qx][ay][ax]=1;
		  q.emplace(0,qy,qx,ay,ax);
		}
		for(Int k=0;k<5;k++){
		  Int ny=qy+dy[k],nx=qx+dx[k];
		  if(!in(ny,nx)||s[ny][nx]=='#') continue;
		  cnt[0][qy][qx][ay][ax]++;
		}
	      }
	      // t == 1
	      {
		for(Int k=0;k<5;k++){
		  Int ny=ay+dy[k],nx=ax+dx[k];
		  if(!in(ny,nx)||s[ny][nx]=='#') continue;
		  if(ny==qy&&nx==qx){		    
		    dp[1][qy][qx][ay][ax]=1;
		    q.emplace(1,qy,qx,ay,ax);		  
		  }
		  cnt[1][qy][qx][ay][ax]++;
		}
	      }
	    }
	  }	
	}
      }
      //cout<<cnt[0][0][0][0][1]<<endl;
      const Int DBG = 0;
      
      while(!q.empty()){
	Int t,qy,qx,ay,ax;
	tie(t,qy,qx,ay,ax)=q.front();q.pop();
	Int d=dp[t][qy][qx][ay][ax];
	if(DBG) cout<<t<<":"<<qy<<" "<<qx<<" "<<ay<<" "<<ax<<":"<<d<<endl;
	
	if(t){
	  for(Int k=0;k<5;k++){
	    Int ny=qy+dy[k],nx=qx+dx[k];
	    if(!in(ny,nx)||s[ny][nx]=='#') continue;
	    if(~dp[!t][ny][nx][ay][ax]) continue;
	    cnt[!t][ny][nx][ay][ax]--;
	    if(!d||cnt[!t][ny][nx][ay][ax]==0){
	      if(DBG) cout<<"->"<<!t<<" "<<ny<<" "<<nx<<" "<<ay<<" "<<ax<<":"<<!d<<endl;
	      dp[!t][ny][nx][ay][ax]=!d;
	      q.emplace(!t,ny,nx,ay,ax);
	    }
	  }
	}else{
	  for(Int k=0;k<5;k++){
	    Int ny=ay+dy[k],nx=ax+dx[k];
	    if(!in(ny,nx)||s[ny][nx]=='#') continue;
	    if(~dp[!t][qy][qx][ny][nx]) continue;
	    cnt[!t][qy][qx][ny][nx]--;
	    if(!d||cnt[!t][qy][qx][ny][nx]==0){
	      if(DBG) cout<<"->"<<!t<<" "<<qy<<" "<<qx<<" "<<ny<<" "<<nx<<":"<<!d<<endl;
	      dp[!t][qy][qx][ny][nx]=!d;
	      q.emplace(!t,qy,qx,ny,nx);
	    }
	  }
	}
      }
      
    }
    
    
    {
      Int qx,qy,ax,ay;
      for(Int i=0;i<h;i++){
	for(Int j=0;j<w;j++){
	  if(s[i][j]=='Q') qy=i,qx=j;
	  if(s[i][j]=='A') ay=i,ax=j;
	}
      }
      if(dp[0][qy][qx][ay][ax]==1)
	cout<<"Queen can escape."<<endl;
      if(dp[0][qy][qx][ay][ax]==0)
	cout<<"Army can catch Queen."<<endl;
      if(dp[0][qy][qx][ay][ax]==-1)
	cout<<"Queen can not escape and Army can not catch Queen."<<endl;
    }
  }
  
  return 0;
}