#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int H,W; cin >> H >> W; vector> A(H,vector(W)); for(auto &h : A) for(auto &w : h) cin >> w; int n = H*W; bool yes = false; for(int i=0; i= 0 && x < H && y >= 0 && y < W){ int now = A.at(i).at(k)+A.at(x).at(y); if(now > 0) yes = true; x += dx,y += dy; } } } if(yes) cout << "infinite\n"; else cout << "finite\n"; } }