#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int N,K;
const int maxn=210;
int visited[maxn][maxn];
char G[maxn][maxn];
struct Point
{
int r,c;//行列
int depth;
int kill;
Point(int rr=0,int cc=0,int dd=0,int kk=0):r(rr),c(cc),depth(dd),kill(kk){};
};//队列
int direct_r[4]={1,0,-1,0};
int direct_c[4]={0,1,0,-1};//控制四个方向
int main()
{
int N,M,S;
cin>>S;
int arrNum = S;
int result[S];
memset(result, -1, sizeof(result));
while(S--)
{
cin>>N>>M;
memset(visited,0,sizeof(visited));
int x;
queue<Point>que;
int I,J;
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
cin>>G[i][j];
if(G[i][j]=='r')
{
que.push(Point(i,j,0,0));
}
else if(G[i][j]=='a') I=i,J=j;
else if(G[i][j]=='#') visited[i][j]=1;
}
}
while(!que.empty())
{
Point s=que.front();
if(s.r==I&&s.c==J)
{
//cout<<s.depth<<endl;
result[S] = s.depth;
break;
}
else
{
if(G[s.r][s.c]=='x'&&s.kill==0)
{
que.push(Point(s.r,s.c,s.depth+1,1));
}
else
{
int rr,cc;
for(int i=0;i<4;i++)
{
rr=s.r+direct_r[i],cc=s.c+direct_c[i];
if(!visited[rr][cc]&&rr>=0&&rr<N&&cc>=0&&cc<M)//未访问
{
visited[rr][cc]=1;//已访问
que.push(Point(rr,cc,s.depth+1,0));
}
}
}
que.pop();
}
}
}
for(int i=arrNum-1; i>=0; i--) {
if (result[i] != -1) {
cout << result[i] << endl;
} else {
cout << "Impossible" << endl;
}
}
return 0;
}