#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ int h, w, v; cin >> h >> w; vector> Y(h), X(w), A(h + w), B(h + w); for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ cin >> v; Y[y].emplace_back(v); X[x].emplace_back(v); A[y + x].emplace_back(v); B[y + (w - 1 - x)].emplace_back(v); } } bool flg = false; for(auto C : {Y, X, A, B}){ for(auto vec : C){ sort(vec.rbegin(), vec.rend()); if(vec.size() >= 2 && vec[0] + vec[1] > 0){ flg = true; break; } } if(flg) break; } cout << (flg ? "infinite" : "finite") << '\n'; } }