//4000多MS过的,数据应该比较大,还是比较简单的
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 1001;
int n;
float G[maxn][maxn];
float Dist[maxn][maxn];
int Q;
int from,to;
int main()
{
while(cin>>n)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
cin>>G[i][j];
}
}
//初始化Dist
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
Dist[i][j] = G[i][j];
}
}
//Floyd算法
for(int k = 0; k < n; k++)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(Dist[i][j] < Dist[i][k] * Dist[k][j])
{
Dist[i][j] = Dist[i][k] * Dist[k][j];
}
//注意是乘而不是加,还有大小
}
}
}
cin>>Q;
for(int i = 0; i < Q; i++)
{
cin>>from>>to;
if(Dist[from-1][to-1] != 0)
{
printf("%.3f\n",Dist[from-1][to-1]);
}
else
cout<<"What a pity!"<<endl;
}
}
return 0;
}