#include <cstdio>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <bitset>

using ll = long long;
auto &is = std::cin;
auto &os = std::cout;

struct Point{
    ll x,y;
};
struct Status{
    Point now;
    ll step;
    bool operator<(const Status &that)const noexcept{
        return this->step > that.step;
    }
};

const ll max_nm {200+5};
const ll ll_max {std::numeric_limits<decltype(ll_max)>::max()};
ll n, h, w, ans{ll_max};
char map[max_nm][max_nm];
Point me;

const int to_next[4][2] {
    {1,0},
    {0,1},
    {-1,0},
    {0,-1},
};

void bfs(const Point start)noexcept{
    std::bitset<max_nm> vis[max_nm];

    std::priority_queue<Status> q;
    ans = ll_max;
    vis[start.x][start.y] = true;

    q.push({start,0});
    while(q.empty()==false){
        const auto status = q.top();
        const auto nowchar = [&status]()->char{return map[status.now.x][status.now.y];};
        q.pop();

        if(nowchar()=='a'){
            ans = std::min(ans,status.step);
            return;
        }
        for(ll i{0};i<4;i++){
            const Point next {status.now.x+to_next[i][0],status.now.y+to_next[i][1]};
            if(vis[next.x][next.y])continue;
            const auto nextchar = [&next]()->char{return map[next.x][next.y];};
            ll cost {1};
            if(next.x>h || next.x<=0 || next.y > w || next.y<=0 
            || nextchar()=='#')continue;
            if(nextchar()=='x')cost++;
            const Status next_status {next,status.step+cost};
            vis[next_status.now.x][next_status.now.y] = true;
            q.push(next_status);
        }
    }
    return;
}

int main(){
    is>>n;
    for(ll _{0};_<n;_++){
        is>>h>>w;
        for(ll i{1};i<=h;i++){
            for(ll j{1};j<=w;j++){
                is>>map[i][j];
                if(map[i][j]=='r')me.x=i,me.y=j;
            }
        }
        bfs(me);
        if(ans==ll_max)os<<"Impossible\n";
        else os<<ans<<'\n';
    }
}