Problem: Aaron is a vicious criminal. He has repeatedly committed crimes (2 shoplifting, 16 peeping, 256 underwear thieves, 65,536 escapes), but has continued to escape from the police with his extraordinary physical abilities. Bruce is a police officer. Although he does not have outstanding athletic ability, he enjoys photography and has the skill to publish his photographs in magazines.

One day Bruce came to take a picture in the mountains. Then I happened to find Aaron's hideout. As Bruce chased Aaron, who escaped, they fell into a pit and wandered into ancient ruins.

The ancient ruins consist of several rooms and passages connecting the rooms. When there are M rooms in the ancient ruins, the rooms in the ruins are numbered from 0 to M-1 respectively.

Aaron thought that it might expire while he was escaping, so he moved through the ruins so that he could continue to escape for the longest time when Bruce moved optimally. Bruce wants to photograph Aaron quickly, so he moves through the ruins so that Bruce can be photographed the fastest when Aaron moves optimally.

Aaron and Bruce act in turn. The first is Aaron's turn. In each turn, you can move to or stay in one of the adjacent rooms. When Aaron and Bruce enter the same room, Bruce shall photograph Aaron.

Find out how long it will take Bruce to shoot Aaron. Time is expressed in terms of the number of turns, and when both Aaron and Bruce have acted once, it is counted as one turn.

For example, in the situation shown in Fig. 5, if Aaron escapes to room 5, Bruce will reach it in 4 turns, but if Aaron escapes to room 7, Bruce will take 5 turns to reach it. For Aaron, the answer is 5 turns because he can escape for the longest time by escaping to room 7.

An example where Aaron can continue to escape for 5 turns.
---
Figure 5: An example where Aaron keeps escaping for 5 turns.

Also, in the situation shown in Fig. 6, Aaron can escape forever by moving the room away from Bruce.

An example of Aaron being able to escape forever.
---
Figure 6: An example of Aaron being able to escape forever.



Input

The first line of input is given the number N (0 <N ≤ 100), which represents the number of datasets. The next line is followed by N datasets.

Each dataset consists of the shape of ancient ruins and the initial positions of Aaron and Bruce. First, the number of rooms in the ancient ruins M (2 ≤ M ≤ 50) is given. Next, a matrix with the number of elements M × M is given. The element of each matrix is ​​0 or 1, and if the jth number in row i is 1, it means that room i and room j are connected by a passage (however, the row and column numbers of the matrix). Counts from 0). The values ​​of the (i, j) and (j, i) components of the matrix are always equal, and the value of the (i, i) component is 0. Then two integers a and b are given. Each integer indicates the room number at the initial position of Aaron (0 ≤ a <M) and the room number at the initial position of Bruce (0 ≤ b <M). The values ​​of a and b are always different.

Output

For each dataset, print in one line how many turns Bruce will take to shoot Aaron. If you can't shoot no matter how much, output "` infinity` ".

Example

Input

6
8
0 1 0 0 0 0 0 0
1 0 1 0 0 0 0 0
0 1 0 1 1 0 0 0
0 0 1 0 0 0 0 0
0 0 1 0 0 1 1 0
0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 1
0 0 0 0 0 0 1 0
3 0
4
0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0
1 0
5
0 1 0 1 0
1 0 0 1 0
0 0 0 0 1
1 1 0 0 0
0 0 1 0 0
2 0
5
0 1 0 0 1
1 0 1 1 1
0 1 0 1 0
0 1 1 0 1
1 1 0 1 0
2 4
5
0 1 0 1 0
1 0 1 1 0
0 1 0 0 1
1 1 0 0 1
0 0 1 1 0
3 0
5
0 1 0 1 1
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
1 1 0 1 0
0 4


Output

5
infinity
infinity
2
infinity
1

Solution (in CPP):

Solution:
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld=long double;

struct Node {
	char var;
	vector<shared_ptr<Node>>chs;
	Node(char ch):var(ch) {

	}
	Node() :var('@') {

	}
};

shared_ptr<Node> term(const vector<int>&ways,map<char,int>mp,string st, int&a,int k) {
	shared_ptr<Node>no;
	if (st[a] == '(') {
		a++;
		auto ans=term(ways,mp,st,a,0);
		assert(st[a]==')');
		a++;
		no=ans;
	}
	else {
		assert(isalpha(st[a]));
		char var = st[a];
		a++;
		no = make_shared<Node>(var);
	}
		
	while (a != st.size() && st[a] != ')') {
		char op = st[a];
			
		if (mp[op] >= k) {
			a++;
			shared_ptr<Node>ans;
			if (ways[mp[op]] == 1) {
				ans = term(ways, mp, st, a, mp[op] + 1);
			}
			else {
				ans = term(ways, mp, st, a, mp[op]);
			}
			shared_ptr<Node>pa(make_shared<Node>(op));
			pa->chs = vector<shared_ptr<Node>>{ no,ans };
			no = pa;
		}
		else {
			break;
		}
	}
	return no;
		
	
}

string get_st(shared_ptr<Node>n) {
	if (isalpha(n->var)) {
		return string(1,n->var);
	}
	else {
		return "("+get_st(n->chs[0])+n->var+get_st(n->chs[1])+")";
	}
}

void solve(string st,map<char,int>ch_mp,const vector<int>&ways) {
	int k=0;
	int a=0;
	shared_ptr<Node>root(term(ways,ch_mp,st,a,0));
	string answer=get_st(root);
	cout<<answer<<endl;
}

struct aa {
	int a_place;
	int b_place;
	int a_turn;
	int cost;
};
int main() {
	int T;cin>>T;
	for (int t = 0; t < T; ++t) {
		int M;cin>>M;
		vector<vector<int>>ad_edges(M,vector<int>(M));
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < M; ++j) {
				cin>>ad_edges[i][j];
				if(i==j)ad_edges[i][j]=true;
			}
		}
		int start_a,start_b;cin>>start_a>>start_b;
		vector<vector<vector<int>>>costs(M,vector<vector<int>>(M,vector<int>(2,10000000)));
		vector<vector<int>>nums(M,vector<int>(M));
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < M; ++j) {
				if (ad_edges[i][j]) {
					for (int k = 0; k < M; ++k) {
						nums[j][k]++;
					}
				}
			}
		}
		queue<aa>que;
		for (int i = 0; i < M; ++i) {
			que.push(aa{ i,i,0,0 });
			costs[i][i][0]=0;
			costs[i][i][1]=0;
			que.push(aa{ i,i,1,0 });
		}
		while (!que.empty()) {
			auto af(que.front());
			que.pop();
			if(af.cost>costs[af.a_place][af.b_place][af.a_turn])continue;
			if (af.a_turn == true) {
				for (int b_from = 0; b_from < M; ++b_from) {
					if (ad_edges[b_from][af.b_place]) {
						if (costs[af.a_place][b_from][0] > af.cost + 1) {
							costs[af.a_place][b_from][0]=af.cost+1;
							que.push(aa{ af.a_place,b_from,0,af.cost + 1 });
						}
					}
				}
			}
			else {
				for (int a_from = 0; a_from < M; ++a_from) {
					if (ad_edges[a_from][af.a_place]) {
						nums[a_from][af.b_place]--;
						if (nums[a_from][af.b_place] == 0) {
							costs[a_from][af.b_place][1]=af.cost;
							que.push(aa{a_from,af.b_place,1,af.cost});
						}
						assert(nums[a_from][af.b_place]>=0);
					}
				}
			}
		}
		int ans=costs[start_a][start_b][1];
		if(ans>10000)cout<<"infinity"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}