#include <bits/stdc++.h>
using namespace std;
int w,h,tim=0;
int a,b,c,d,ni,nj,ans,f;
char ch;
int mx[4]={1,0,0,-1},
my[4]={0,1,-1,0};
bool mp[80][80];
bool vis[80][80];
struct po
{
int x,y,st,drkt;
};
bool check(int x,int y)
{
if(x<0||x>h+1||y<0||y>w+1||vis[x][y]||mp[x][y])
return 0;
return 1;
}
void bfs(int t,int x,int y)
{
queue <po> q;
vis[x][y]=1;
q.push((po){x,y,0,4});
while(q.size())
{
int xx=q.front().x;int m=q.front().drkt;
int yy=q.front().y;int s=q.front().st;
q.pop();
for(int i=0;i<4;i++)
{
int xxx=xx+mx[i];
int yyy=yy+my[i];
if(xxx==d&&yyy==c)
{
int ss=(i!=m)?s+1:s;
f=1;
ans=min(ans,ss);
continue;
}
if(check(xxx,yyy))
{
int ss=(i!=m)?s+1:s;
vis[xxx][yyy]=1;
q.push((po){xxx,yyy,ss,i});
}
}
}
if(f)
{
printf("Pair %d: %d segments.",t,ans);
cout<<endl;
}
else
{
printf("Pair %d: impossible.",t);
cout<<endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);cin.tie(NULL);
while(cin>>w>>h,w)
{
int t=0;
memset(mp,0,sizeof(mp));
cout<<"Board #:"<<++tim<<endl;
for(int i=1; i<=h; i++)
{
for(int j=1; j<=w; j++)
{
char ch = getchar();
while(ch != ' ' && ch != 'X') {
ch = getchar();
}
if(ch=='X') mp[i][j]=1;
}
}
while(cin>>a>>b>>c>>d,a)
{
memset(vis,0,sizeof(vis));
ans=0x3f3f3f3f;f=0;
bfs(++t,b,a);
}
cout<<endl;
}
}