http://acm.hdu.edu.cn/showproblem.php?pid=1596

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG

using namespace std;
typedef long long ll;
const int N=10000;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int s,t,n,m,q;
struct node{
    int e;
    double w;
};
struct cmp{
    bool operator()(const node &a,const node &b){
            return a.w<b.w;
    }
};
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    while(~scanf("%d",&n)){
        double d;
        vector<node>v[1001];
        node x;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                scanf("%lf",&d);
                if(d!=0){
                    x.e=j,x.w=d;
                    v[i].push_back(x);
                }
            }
        }
        scanf("%d",&q);
        while(q--){
            scanf("%d%d",&s,&t);
            priority_queue<node,vector<node>,cmp>que;
            int vis[1001]={0};
            x.e=s,x.w=1;
            que.push(x);
            while(!que.empty()){
                x=que.top();

                vis[x.e]=1;
                if(x.e==t)
                    break;
                que.pop();
                for(int i=0,j=v[x.e].size();i<j;i++){
                    node q;
                    q.e=v[x.e][i].e;
                    if(vis[q.e])
                        continue;
                    q.w=v[x.e][i].w*x.w;
                    que.push(q);
                }

            }
            if(x.e!=t)
                cout << "What a pity!" << endl;
            else
                printf("%.3f\n",x.w);

        }
    }

    //cout << "Hello world!" << endl;
    return 0;
}