#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int h, w; cin >> h >> w; vector> a(h, vector(w)); rep(i, h) rep(j, w) cin >> a[i][j]; bool ok = true; rep(i, h) rep(j, w) rep(x, h) rep(y, w) { if (i == x && j == y) continue; if (i == x || j == y || abs(i - x) == abs(j - y)) { if (a[i][j] + a[x][y] > 0) ok = false; } } cout << (ok ? "finite" : "infinite") << endl; } return 0; }