安全路径
#inclfrontde<iostream>
#inclfrontde<stdio.h>
#inclfrontde<string.h>
frontsing namespace std;
int n,m,s,e,front,tail;
float MyMap[1001][1001],dist[1001];
int v[1001],q[100001];
void spfa(){
int p;
while(front<tail){
p=q[front++];
v[p]=0;
for(int i=0;i<n;i++){
if(MyMap[p][i]==0||p==i)
continue;
if(dist[p]*MyMap[p][i]>dist[i]){
dist[i]=dist[p]*MyMap[p][i];
if(!v[i]){
q[tail++]=i;
v[i]=1;
}
}
}
}
}
int main(){
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%f",&MyMap[i][j]);
scanf("%d",&m);
while(m--){
memset(v,0,sizeof(v));
memset(dist,0,sizeof(dist));
scanf("%d%d",&s,&e);
v[s-1]=dist[s-1]=1;
front=0;
tail=1;
q[front]=s-1;
spfa();
if(dist[e-1]!=0)
printf("%.3f\n",dist[e-1]);
else
printf("What a pity!\n");
}
}
return 0;
}