#include #define ull unsigned ll #define ll long long #define ld long double #define INFL (ll)3e18 #define INF (int)2e9 #define MOD (ll)998244353 #define MODO (ll)(1e9+7) using namespace std; templateistream&operator>>(istream&is,vector&v); templateistream&operator>>(istream&is,tuple& t); templateistream&operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} templateistream&operator>>(istream&is,vector&v){for(T&in:v)is>>in;return is;} templateistream& operator>>(istream& is, tuple& t) {apply([&](auto&... args) {((is >> args), ...);},t);return is;} int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--){ int h,w; cin >> h >> w; vector> a(h,vector(w)); cin >> a; ll ma = 0; for(int i = 0;i < h;i++){ for(int j = 0;j < w;j++){ for(int k = 0;k < j;k++){ ma = max(ma,a[i][j]+a[i][k]); } } } for(int i = 0;i < h;i++){ for(int j = 0;j < w;j++){ for(int k = 0;k < i;k++){ ma = max(ma,a[i][j]+a[k][j]); } } } for(int i = 0;i < h;i++){ for(int j = 0;j < w;j++){ for(int k = 0;i+k=0;k++){ ma = max(ma,a[i][j]+a[i+k][j-k]); } } } if(ma > 0) cout << "infinite" << endl; else cout << "finite" << endl; } }