#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--){ int h, w; cin >> h >> w; vector> a(h, vector (w)); for(auto &ee: a) for(auto &e: ee) cin >> e; bool b = true; for(auto ee: a){ for(auto e: ee){ if(e > 0) { b = false; cout << "infinite" << '\n'; break; } } if(!b) break; } if(b) cout << "finite" << '\n'; } return 0; }