#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { int h, w; cin >> h >> w; vector a(h, vector(w)); rep(i, 0, h) rep(j, 0, w) cin >> a[i][j]; rep(i0, 0, h) rep(j0, 0, w) { rep(i1, i0, h) rep(j1, 0, w) { if (i0 * w + j0 >= i1 * w + j1) continue; if (i0 == i1 || j0 == j1 || i0 + j0 == i1 + j1 || i0 - j0 == i1 - j1) { if (a[i0][j0] + a[i1][j1] > 0) { cout << "infinite \n"; return; } } } } cout << "finite\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; cin >> t; while (t--) solve(); }